Reputation: 13335
I need to determine if a record with a given value exists in a list, what is the most efficient way to do this?
Upvotes: 0
Views: 138
Reputation: 8548
i think like this:
[ L || L = #record{state=determined} <- List ].
And the most efficient way is:
lists:any(fun(#record{state=deter}) -> true; (_) -> false end, List).
The first aproach is applicable if your list contains few records with determined field in the list and you'll get it all. The second aproach is the most efficient because we are using standart library and if we'll get nedeed record we'll will stop iteration over the list.
Upvotes: 1