[erlang-questions] lists:keyfind as an alternative to lists:keysearch
zambal
zambal@REDACTED
Wed Jan 21 16:15:11 CET 2009
On 21 jan, 14:46, mats cronqvist <ma...@REDACTED> wrote:
> Bjorn Gustavsson <bgustavs...@REDACTED> writes:
>
> > For consistency with the rest of the lists module (and in particular
> > the keysearch/3 function) I think that 'false' is the best value.
>
> > (In general, I agree that "half booleans" should be avoided
> > in new code.)
>
> so doing it Right(tm), i.e. returning the value if found or exit(),
> is out of the question?
> seems i've written this function at least a thousand times;
>
> keyfind(Key,N,List) ->
> {value,{Key,Val} = lists:keysearch(Key,N,List),
> Val.
>
> mats
> _______________________________________________
> erlang-questions mailing list
> erlang-questi...@REDACTED://www.erlang.org/mailman/listinfo/erlang-questions
As a lightweight dictionary alternative, I like Mats' suggestion best:
give back the value, otherwise crash.
Best,
Vincent
More information about the erlang-questions
mailing list