[erlang-questions] Doubt with lists:dropwhile

James Aimonetti james@REDACTED
Wed Apr 25 19:51:16 CEST 2012


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

lists:dropwhile/2 discards list elements while the fun returns true.
The first element of the list, <<"HTTP/1.1 205 Reset Content">>, does
not equal the empty binary, returns false, which ends the dropwhile/2,
having dropped no elements.

Are you trying to filter out the empty binary?

[ E || E <- binary:split(Data, <<"\r\n">>, [trim, global]), E =/= <<>>].

That will filter out all empty binaries.

On 04/25/2012 10:34 AM, Farruco Sanjurjo 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?
> 
> 
> 
> 
> _______________________________________________ erlang-questions
> mailing list erlang-questions@REDACTED 
> http://erlang.org/mailman/listinfo/erlang-questions


- -- 
James Aimonetti
Distributed Systems Engineer / DJ MC_

2600hz | http://2600hz.com
sip:james@REDACTED
tel: 415.886.7905
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJPmDmUAAoJENc77s1OYoGgdsQH/1UHoHzlgMxsAToCTUtMGgP4
qBtM62soVTPAeNNrLEPBokY8Jv0qpDPVI2cQeDRLHqrvi5JfVaAK09gIUrMbluNi
KGr1MqH5GsYS+SVeUgKRwfvKpuKijzGDzY0pFLLywvXtRAw/5WO2YuLYC9oV7vD1
ixgaRQMOiie3TkO5igdDo72mlhtdyREizxdrGD8BBIb6mpKMnP1wVc7tabKYgZF5
xiQUbtMbaEbEbstQSDMiDDNy6hl86S8kj1eCJqGtggTirCII3fvk5Qqm13Q5sVEc
65HPhrab+PbUS4K74LAyqfwlcUK04CVS4qCkaHoJCfOBfZPoXMCQtwX/Vj6Zp58=
=GVoj
-----END PGP SIGNATURE-----



More information about the erlang-questions mailing list