Re: Add lists:find/2,3
Masklinn <[email protected]>
| Newsgroups | gmane.comp.lang.erlang.patches |
|---|---|
| Message-ID | <[email protected]> |
On 2013-10-14, at 12:28 , Anthony Ramine wrote:
> Hello Sean,
>
> I don't like this patch.
>
> 1/ You can't know whether an element was found or not if the list elements are arbitrary terms.
You also can't assert that an element was found in the usual manner
(namely {ok, Result} = fun:call())
> 2/ I don't see why you would say people hack either foreach/2 or foldl/3 to do that when they should just use dropwhile/2.
>
> A naive implementation of find/2 using dropwhile/2:
>
> find(F, L) ->
> case dropwhile(fun (E) -> not F(E) end, L) of
> [] -> undefined;
> [E|_] -> E
> end.
>
> Regards,
>
> --
> Anthony Ramine
_______________________________________________
erlang-patches mailing list
[email protected]
http://erlang.org/mailman/listinfo/erlang-patches