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

mats cronqvist masse@REDACTED
Wed Jan 21 16:40:32 CET 2009


Bjorn Gustavsson <bgustavsson@REDACTED> writes:

> On Wed, Jan 21, 2009 at 2:46 PM, mats cronqvist <masse@REDACTED> wrote:
>>  so doing it Right(tm), i.e. returning the value if found or exit(),
>>  is out of the question?
>
> Yes. :-)

   damn. i guess i'll have to fork OTP then.

>>  seems i've written this function at least a thousand times;
>>
>> keyfind(Key,N,List) ->
>>  {value,{Key,Val} = lists:keysearch(Key,N,List),
>>  Val.
>
> This version only works for tuples of size 2.

  it was meant as an example, not an implementation proposal. i didn't
  balance the braces either :<

  mats



More information about the erlang-questions mailing list