simple standard library additions

James Hague james.hague@REDACTED
Thu Jun 15 17:27:19 CEST 2006


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.)

min(X,Y) when X =< Y -> X;
min(_,Y) -> Y.

max(X,Y) when X >= Y -> X;
max(_,Y) -> Y.

% Wrapper for functions that return {ok,Something}.
ok({ok,Data}) -> Data.

% Should be in lists.
keyfind(Key, N, TupleList) ->
   case lists:keysearch(Key, N, TupleList) of
      {value,X} -> X;
      false -> false
   end.



More information about the erlang-questions mailing list