[erlang-bugs] lists:dropwhile

Robert Virding rvirding@REDACTED
Fri Jun 13 16:28:04 CEST 2008


It is *supposed* to drop the elements of a list as long as they evaluate the
predicate to 'true'. As soon as the predicate evaluates to false then that
element and the rest of the list are returned. It is *not* the equivalent of
filter/2 with the inverse test.
Robert


2008/6/13 Matt Handler <matt.handler@REDACTED>:

> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-bugs/attachments/20080613/e02d38c6/attachment.htm>


More information about the erlang-bugs mailing list