[erlang-patches] Add lists:find/2,3

Masklinn <>
Mon Oct 14 12:38:55 CEST 2013


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



More information about the erlang-patches mailing list