LambdaJCollection: analogue to select or filter

16 views
Skip to first unread message

Dmitriy Vsekhvalnov

unread,
Mar 10, 2012, 9:10:29 AM3/10/12
to lam...@googlegroups.com
Hi,
  i'm looking for syntax sugar in LambdaJCollection to work the same as Lambda.filter(..).

E.g.

with(mydata).retain(...)  - hava side effect, that it modifies 'mydata' collection. And  don't want to do:

with(mydata).clone().retain(..) - because 'mydata' can be pretty big, and i'm looking for ~1-5% of it.

But i can't see if i can do: with(mydata).filter(..)  - would be nice to have it.


Mario Fusco

unread,
Mar 10, 2012, 10:14:38 AM3/10/12
to lam...@googlegroups.com
Hi Dmitriy,

thanks for your interest in lambdaj.
In your case I suggest to pass to the with constructor not the list but an iterator on it like in:

with(mydata.iterator()).retain(...)

In this way you will also have the useful side effect that the filter condition will be evaluated lazily only if and when you call next on the resulting LambdaIterator. It means that you don't have to traverse the whole list and evaluate all the items in it if you need, let's say, only the first 10 items that match the filter. Does this make sense?

Mario

Dmitriy Vsekhvalnov

unread,
Mar 10, 2012, 10:27:58 AM3/10/12
to lam...@googlegroups.com
Absolutely, thanks.

But why don't you add it interface? It will make programs more readable and you will not describe this trick in mail list to other person :)
Reply all
Reply to author
Forward
0 new messages