[erlang-questions] Weird lists:dropwhile/2 behavior?

Sergej Jurečko <>
Sun Feb 21 14:34:22 CET 2016


You probably should be using lists:filter for K, or better yet a list comprehension. 
lists:dropwhile will stop processing as soon as K returns false.

Sergej

> On 21 Feb 2016, at 13:39, fxmy wang <> wrote:
> 
> Hello guys,
> 
> Just encountered this:
> Erlang/OTP 18 [erts-7.0.3] [source-5991161] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false]
> 
> Eshell V7.0.3  (abort with ^G)
> 1> F = fun(_) -> true end.
> #Fun<erl_eval.6.54118792>
> 2> K = fun(Elem) -> Elem > 3 end.
> #Fun<erl_eval.6.54118792>
> 3> lists:dropwhile(F, [1,2,3,4,5]).
> []
> 4> lists:dropwhile(K, [1,2,3,4,5]).
> [1,2,3,4,5]
> Is this behavior expected?
> Am I missing something?
> 
> ​​
> 
> 
> 
> 
> ​Cheers,
> 
> 
> Fxmy.​
> 
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20160221/4edd5ae4/attachment.html>


More information about the erlang-questions mailing list