[erlang-questions] Best way to test if empty dict/set/etc.?
Fri May 31 00:17:37 CEST 2013
I noticed that a lot of the opaque data structures don't have an
is_empty predicate. What is the best way to test if one of these is
empty? Preferably an O(1) test, not size(X)==0 (unless that is O(1)),
because the structure might be quite large.
One way I thought of is to use fold on a function that just throws:
catch dict:fold(fun (_,_) -> throw(false) end, true, Dict).
But that is disturbingly ugly. Is there a preferred way to do this?
More information about the erlang-questions