lambdaj fluent interface collections

130 views
Skip to first unread message

Mario Fusco

unread,
Jul 4, 2010, 10:25:38 AM7/4/10
to lambdaj
Here you can find a first brief description of the fluent interface
collections that will be available in the upcoming release 2.3 of
lambdaj:

http://code.google.com/p/lambdaj/wiki/LambdaCollections

Any feedback?

Cheers,
Mario

Alison Winters

unread,
Jul 4, 2010, 9:29:21 PM7/4/10
to lambdaj
Looks great! I think as long as there is an option to create a copy of
the original collection it will suit nicely (e.g.
with(copyOf(myCollection)).remove(nullValue()); ). This may be
convenient for cases where the collection is a list of JPA entities;
we don't want to accidentally cascade delete entities from the
database if all we are doing is filtering. On the other hand,
sometimes we may want exactly that behavior.

Alison

Mario Fusco

unread,
Jul 6, 2010, 5:41:39 PM7/6/10
to lambdaj
Hi Alison,

it will be possible to work on a copy of the original collection by
simply cloning it as it follows:

with(myCollection).clone().remove(nullValue());

I will update the wiki page accordingly.
Let me know if this approach makes sense to you.

Thanks a lot

Bye
Mario

Alison Winters

unread,
Jul 8, 2010, 3:03:22 PM7/8/10
to lambdaj
Hi Mario,

clone() tends to fire warning sirens for me because it's usually
implemented badly, but this behavior would match that of API classes
like ArrayList and HashSet so i think if it's documented well it would
be a good solution :)

Alison

Andrey Belyaev

unread,
Aug 23, 2010, 7:31:58 AM8/23/10
to lambdaj
Hi Mario,

I have a couple of suggestions on fluent interfaces.
1. Can we have an implementaions of removeAll and retainAll which will
return the result collection without modifications of existing? The
case is the following - I have two collections A and B and need to get
A-B, B-A and A intersect B and the for each of resulting collections
do some filtering,grouping etc. We can call them "minus" and
"intersect".
2. In the implementation of Map it would be great to have
getAll(Collection col) method which will return all values for a
collection of keys. The use case is that we can filter somehow the
collection of keys and them get all the values instead of iterating
over all keys.

Please let me know if you think that these are the common cases and
can include into lambdaj API.

Thanks,
Andrey

Mario Fusco

unread,
Aug 24, 2010, 3:41:53 AM8/24/10
to lam...@googlegroups.com
I have a couple of suggestions on fluent interfaces.
1. Can we have an implementaions of removeAll and retainAll which will
return the result collection without modifications of existing? The
case is the following - I have two collections A and B and need to get
A-B, B-A and A intersect B and the for each of resulting collections
do some filtering,grouping etc. We can call them "minus" and
"intersect".

If I have well understood what you are asking you can already do that by putting the result of the intersection in a fluent collection as it follows:

with(collA.retainAll(collB)).group(...) ...

Do you agree?
 
2. In the implementation of Map it would be great to have
getAll(Collection col) method which will return all values for a
collection of keys. The use case is that we can filter somehow the
collection of keys and them get all the values instead of iterating
over all keys.

Yes, that makes lot of sense. It will be part of the next release.

Thank you for your suggestions

Bye,
Mario

P.S.: I just checked that the release 2.3.1 is now available even in the central maven repository. Let me know if it is all ok with it.

Andrey Belyaev

unread,
Aug 24, 2010, 7:39:03 AM8/24/10
to lambdaj
> If I have well understood what you are asking you can already do that by
> putting the result of the intersection in a fluent collection as it follows:
>
> with(collA.retainAll(collB)).group(...) ...
>
> Do you agree?

Methods removeAll and retainAll have the return type of boolean - it
reflects whether the collection is changed after an operation. This
breaks the call chain, doesn't it?

Thanks for the getAll() it will be helpful for me.

P.S. confirm that now all is ok with 2.3.1.
P.P.S. can you comment on my last message in
http://groups.google.com/group/lambdaj/browse_thread/thread/7d22aa6e4f9ccd77
thread?

Thanks for everything,
Andrey

Richard Emerson

unread,
Jan 10, 2014, 11:54:41 AM1/10/14
to lam...@googlegroups.com
Hi,

This stuff is really awesome, and very valuable for those of us who aren't able to go to Java 8 yet!

I'm looking for the method which applies a Closure to each element of a collection, and I can't seem to find it... am I missing something?

In other words, I want to do something like this:

Closure printIt = closure(); { of(System.out).println(var(String.class)); }
List<String> things = Arrays.asList("One", "Two", "Three");
with(things).apply(printIt);

Many thanks,
Richard
Reply all
Reply to author
Forward
0 new messages