Findfirst for Dicts with `nothing` keys

Since any value could be a dictionary key (including missing or an array), there is nothing (no pun intended) that findfirst could return on failure that couldn’t collide with a key. You’d have to throw an exception instead, which is conceptually fine but would be much slower.

In the rare (but not impossible) case of dictionaries that may have nothing as a key and you need linear search, the best alternative is probably just to write your own loop, which is not any slower than findfirst and takes 4 lines instead of 1.

for v in values(d) # or (k,v) in pairs(d)
      v == 1 && return something
end
return somethingelse
2 Likes