[erlang-questions] Doubt with lists:dropwhile

Farruco Sanjurjo madtrick@REDACTED
Wed Apr 25 20:08:11 CEST 2012


You both are right. It was a misinterpretation : )

Thanks

P.S: Bob and Jesse, sorry for the previous responses. I click "Reply"
instead of "Reply to all". Shame on me : (

On 25 April 2012 19:49, Jesse Gumm <gumm@REDACTED> wrote:

> 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
> just returned.
>
> Easy Example:
>
> > LessThan5 = fun(X) X < 5 end.
>
> > lists:dropwhile(LessThan5,[1,2,3,4,5,6]).
> [5,6]
>
> >lists:dropwhile(LessThan5,[6,5,4,3,2,1]).
> [6,5,4,3,2,1]
>
> -Jesse
>
> On Wed, Apr 25, 2012 at 12:34 PM, 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?
> >
> >
> > _______________________________________________
> > erlang-questions mailing list
> > erlang-questions@REDACTED
> > http://erlang.org/mailman/listinfo/erlang-questions
> >
>
>
>
> --
> Jesse Gumm
> Owner, Sigma Star Systems
> 414.940.4866 || sigma-star.com || @jessegumm
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120425/bbebe06e/attachment.htm>


More information about the erlang-questions mailing list