simple standard library additions

Robert Virding robert.virding@REDACTED
Thu Jun 15 23:18:11 CEST 2006


James Hague wrote:
> These are things I write all the time, and they'd be nice to roll into
> the standard library (preferably without having to prefix "erlang:"
> before each use).  (Note that there's a min/1 and max/1 in lists, but
> not the simplest case.)
> ...
> % Should be in lists.
> keyfind(Key, N, TupleList) ->
>   case lists:keysearch(Key, N, TupleList) of
>      {value,X} -> X;
>      false -> false
>   end.

What happens if the value X is false? That's why it is wrapped. Or did 
you mean that it should generate an error if not found. Dict separates 
these two cases with dict:find has the wrapped value and dict:fetch 
returns the value or else generates an error if not found.

Robert



More information about the erlang-questions mailing list