It seems to be a common pattern to me that something like this needs to be done:
if !haskey(dict, key) ... else item = dict[key] ... end
Would this lead to two lookups and thus cause extra overhead?
I considered using
get/3 but it can only go so far as to provide a default value. In cases where more complicated operations instead of just getting a value is needed, I still need to write
item = get(dict, key, nothing) if item == nothing # do stuffs else # do stuffs with item end
which still involves an extra comparison operation and doesn’t seem to be sensible code at all.
AFAIK in languages such as Rust there seem to be special constructs that help deal with such cases with a Dict.
What’s the idiomatic way to do so? Or is it just simply not a performance concern due to some sort of optimization, and I shouldn’t worry about using
!haskey in this scenario?