[erlang-questions] lists:mapfind?

Richard A. O'Keefe <>
Tue Aug 22 05:01:03 CEST 2017



On 22/08/17 4:18 AM, Lukas Larsson wrote:
> I agree with Richard that lists:first/2[1] is missing.

> [1]: though I think it should be called lists:find/2 for consistency
> with lists:keyfind/3 and to not be confused as the opposite of lists:last/1

lists:first/2 is the opposite of lists:last/2.

I thought I included that.  If not,

last(Pred, [X|Xs]) ->
     case Pred(X)
       of true  -> last_aux(Pred, Xs, X)
        ; false -> last(Pred, Xs)
     end;
last(_, []) ->
     error.

last_aux(Pred, [X|Xs], Y) ->
     last_aux(Pred, Xs, case Pred(X)
                          of true  -> X
                           ; false -> Y
                        end);
last_aux(_, [], Y) ->
     {ok, Y}.



More information about the erlang-questions mailing list