. , / ( , ).
-module(lazy_first).
-export([first/3]).
first(L, Condition, Default) ->
first(L, [], Condition, Default).
first([E | Rest], Acc, Condition, Default) ->
case Condition(E) of
true -> E;
false -> first(Rest, [E | Acc], Condition, Default)
end;
first([], _Acc, _Cond, Default) -> Default.
:
14> lazy_first:first([1, 2, 3, 4, 5], fun(E) -> E > 2.5 end, 0.0).
3
15> lazy_first:first([1, 2, 3, 4, 5], fun(E) -> E > 5.5 end, 0.0).
0.0
Edit
.
first([E | Rest], Condition, Default) ->
case Condition(E) of
true -> E;
false -> first(Rest, Condition, Default)
end;
first([], _Cond, Default) -> Default.