[erlang-questions] lists:takewhile and lists:splitwith

maruthavanan s <>
Thu Feb 3 11:09:46 CET 2011


Hi,

Sorry for the confusion.

It was my mistake, I was reading the list document and got confused with "splitwith" /"takewhil"/ "dropwhile".

Got it.

Thanks,
Marutha

> From: 
> Date: Thu, 3 Feb 2011 11:02:25 +0100
> CC: 
> To: 
> Subject: Re: [erlang-questions] lists:takewhile and lists:splitwith
> 
> On 2011-02-03, at 10:56 , maruthavanan s wrote:
> > Hi,
> > 
> > The document says lists:takewhile(Pred,List) would return tuple of lists which would split the List when Pred returns true.
> > 
> > I tried the below.
> > 
> > lists:takewhile(fun(A)-> A==3 end,[1,2,3,4,5]).
> > 
> > it gives me an empty result.. What should I do to  get {[1,2],[3,4,5]}
> I don't know which documentation you read, mine says the following:
> 
>   takewhile(Pred, List1) -> List2
>     Takes elements Elem from List1 while Pred(Elem) returns true, that is, the function returns the longest prefix of the list for which all elements satisfy the predicate.
> 
> Here, the first element of `List1` is `1`, for which `Pred` is `false`, so `takewhile` returns an empty list. Sounds sensible and works as I would expect.
> 
> What you seem to describe is lists:splitwith[0], and note that in any case your predicate is incorrect.
> 
> [0] http://www.erlang.org/doc/man/lists.html#splitwith-2
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:
> 
 		 	   		  


More information about the erlang-questions mailing list