Remove cumulate from Stream interface (original) (raw)

Brian Goetz brian.goetz at oracle.com
Wed Dec 5 07:05:24 PST 2012


Only if you don't care about parallel, and the whole value of cumulate is that prefix shows up everywhere in parallel algorithms.

Plus, your Mapper will violate the to-be-written specs about statefulness/side-effects in lambdas passed to functional stream methods.

On 12/5/2012 9:33 AM, Remi Forax wrote:

I maybe wrong but there is a simple way to implement cumulate() using map(), so I'm not sure cumulate pull its own weight.

Rémi public final Stream cumulate(final BinaryOperator operator) { return map(new Mapper<U,U>() { private Object accumulator = NOVALUE; @Override public U map(U element) { Object acc = accumulator; if (acc == NOVALUE) { return element; } acc = operator.operate((U)acc, element); accumulator = acc; return (U)acc; } }); }



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