[erlang-questions] Weird lists:dropwhile/2 behavior?
Dmitry Kolesnikov
dmkolesnikov@REDACTED
Sun Feb 21 14:35:23 CET 2016
Hello,
This is correct behavior.
http://erldocs.com/17.5/stdlib/lists.html?i=1&search=lists:drop#dropwhile/2
"Drops elements Elem from List1 while Pred(Elem) returns true and returns the remaining list."
Your first case: the predicate return true, empty list is the correct result.
Your second case: the predicate return false for the first element, remaining list is returned.
- Dmitry
> On Feb 21, 2016, at 2:39 PM, fxmy wang <fxmywc@REDACTED> 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
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
More information about the erlang-questions
mailing list