[erlang-questions] lists:keyfind as an alternative to lists:keysearch

Bjorn Gustavsson bgustavsson@REDACTED
Wed Feb 4 11:10:50 CET 2009


On Tue, Jan 20, 2009 at 4:15 PM, James Hague <james.hague@REDACTED> wrote:
>
> I would like to propose the addition of lists:keyfind/3, which is
> identical in structure to lists:keysearch/3, except that it returns
> either 'false' or the found tuple, with no additional wrapping of the
> result.  This can be trivially added to the lists module:
>
>   keyfind(K, N, L) ->
>      case keysearch(K, N, L) of
>         {_, Tuple} -> Tuple;
>         X -> X
>      end.
>
> But ideally it would be a BIF (like lists:keysearch) to avoid
> construction of the tagged tuple.  At the moment, association lists
> and the "key" functions are one of the best alternatives to
> lightweight dictionaries.  With this proposed change, they'd be even
> lighter weight and simpler to use.

We have decided to implement lists:keyfind/3 as a BIF in R13.
Its behavior will be exactly as suggested.

/Bjorn

-- 
Björn Gustavsson, Erlang/OTP, Ericsson AB



More information about the erlang-questions mailing list