[erlang-questions] Doubt with lists:dropwhile
Wed Apr 25 19:49:19 CEST 2012
This is a misinterpretation of lists:dropwhile.
lists:dropwhile will remove elements of a list starting with the first
and iterate through the list, continuing to drop elements as long as
the predicate returns true. However, as soon as the predicate returns
false, it'll just stop and return.
So in your case, the dropwhile didn't match the first element, so it
> LessThan5 = fun(X) X < 5 end.
On Wed, Apr 25, 2012 at 12:34 PM, Farruco Sanjurjo <> wrote:
> I'm not getting the expected result while using lists:dropwhile/2
> Here is an example of my problem:
> Data = <<"HTTP/1.1 205 Reset Content\r\n
> Header-A: A\r\n
> Header-C : dGhlIHNhbXBsZSBub25jZQ==\r\n
> Header-D: D\r\n\r\n
> lists:dropwhile(fun(E) -> E == <<>> end, binary:split(Data, <<"\r\n">>,
> [trim, global])).
> And this is the result:
> [<<"HTTP/1.1 205 Reset Content">>,
> <<"\n Header-A: A">>,
> <<"\n Header-C dGhlIHNhbXBsZSBub25jZQ==">>,
> <<"\n Header-D: D">>,<<>>,
> <<"\n ">>]
> But on the result above, there's a <<>> which if I understand the manpage of
> lists:dropwhile shouldn't be there.
> Am I misunderstanding something?
> erlang-questions mailing list
Owner, Sigma Star Systems
414.940.4866 || sigma-star.com || @jessegumm
More information about the erlang-questions