Yet another run at reduce (original) (raw)

Remi Forax forax at univ-mlv.fr
Tue Jan 8 10:19:30 PST 2013


On 01/08/2013 06:08 PM, Brian Goetz wrote:

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.

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: 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.

Then into() goes away. Then sequential() goes away.

yes.

Rémi

On 1/8/2013 11:37 AM, Tim Peierls wrote: On Tue, Jan 8, 2013 at 11:18 AM, Brian Goetz <brian.goetz at oracle.com_ _<mailto:brian.goetz at oracle.com>> wrote: Where intoCollection is a simple Reducer: Reducer<T,C> intoCollection(Supplier collectionFactory) { _return leftCombiningReducer(collectionFactory, Collection::add, Collection::addAll); }

And leftCombiningReducer builds a reducer out of its arguments, which correspond to makeResult, accumulate, and combine? --tim



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