On Sunday, 1 September 2024 at 08:50:53 UTC, ryuukk_ wrote:

if checking for/getting a value from a hashmap requires all that crap, then perhaps something is wrong with the language, and it perhaps isn't the one i should have picked for the task

my mistake perhaps, not yours


besides, i do use the language features in my project, templates and mixins to solve larger problems, it's great, and reason why i picked D



An alternative would be yet another template wrapper for get value that takes a dictionary an a lambda and call that lambda only if value is present, this means you no longer do the if, but rather a "cryptic" call like in some other languages.

pseudo code:
```d
// helper function
void withKey(V,K,L)(V[K] dict, K key, lazy L dostuff) {
    if (auto value = dict.get(K)) {
        doStuff(*value);
    }
}

// usage

string[int] counters;
counters["foo"] = 42;
counters.withKey("foo", (value) {
    assert(value == 42);
});
```
    • Re: Associa... ryuukk_ via Digitalmars-d-learn
      • Re: Ass... Lance Bachmeier via Digitalmars-d-learn
        • Re:... ryuukk_ via Digitalmars-d-learn
        • Re:... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
      • Re: Ass... Nick Treleaven via Digitalmars-d-learn
        • Re:... Nick Treleaven via Digitalmars-d-learn
        • Re:... Nick Treleaven via Digitalmars-d-learn
  • Re: Associative ... kdevel via Digitalmars-d-learn
    • Re: Associa... Paul Backus via Digitalmars-d-learn
      • Re: Ass... ryuukk_ via Digitalmars-d-learn
        • Re:... evilrat via Digitalmars-d-learn

Reply via email to