Yet another run at reduce (original) (raw)

Brian Goetz brian.goetz at oracle.com
Tue Jan 8 10:40:02 PST 2013


And then...

into(collection) becomes reduce(intoList()) reduce(intoSet()) I think, I prefer, reduce(toList()) and reduce(toSet()), because their semantics is slightly different than into.

That's reasonable.

reduce(intoCollection(ArrayList::new))

where intoList() could be as simple as: public static Reducer<T,List> intoList() { return intoCollection(ArrayList::new); } and intoCollection is as shown below. intoCollection should specifies that the supplier can be called several times, so it should always returns a new collection, i.e. this doesn't work:

Right. Needs to be doc'ed.

public static Reducer<T,List> intoList() { ArrayList list = new ArrayList<>(); return intoCollection(() -> list); }

I fear that people will write something like that and only test with a serial stream.

A valid fear :(



More information about the lambda-libs-spec-observers mailing list