[erlang-bugs] lists:dropwhile
Bengt Kleberg
bengt.kleberg@REDACTED
Fri Jun 13 16:24:56 CEST 2008
Greetings,
The documentation of dropwhile/ 2 says:
"Drops elements Elem from List1 while Pred(Elem) returns true and
returns the remaining list."
bengt
On Fri, 2008-06-13 at 09:55 -0400, Matt Handler wrote:
> dropwhile does not work properly as defined in R12B-2:
>
> 01 dropwhile(Pred, [Hd|Tail]=Rest) ->
> 02 case Pred(Hd) of
> 03 true -> dropwhile(Pred, Tail);
> 04 false -> Rest
> 05 end;
> 06 dropwhile(Pred, []) when is_function(Pred, 1) -> [].
>
> it returns the entire list once it finds an element that doesn't match
> true.
>
> here's what i did instead:
>
> dropwhile(Fun, List) ->
> [Element ||
> Element <- List,
> Fun(Element) =/= true].
>
> thanks,
> -matt
> _______________________________________________
> erlang-bugs mailing list
> erlang-bugs@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-bugs
More information about the erlang-bugs
mailing list