[erlang-questions] Doubt with lists:dropwhile
Bob Ippolito
bob@REDACTED
Wed Apr 25 19:47:58 CEST 2012
On Wed, Apr 25, 2012 at 10:34 AM, Farruco Sanjurjo <madtrick@REDACTED>wrote:
> Hi,
>
> 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?
>
It sounds like you are looking for lists:filter/2, lists:dropwhile/2 drops
from the head of the list until F returns false, then it simply returns the
rest of the list.
-bob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120425/6a7f7fb1/attachment.htm>
More information about the erlang-questions
mailing list