Remove cumulate from Stream interface

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<U> cumulate(final BinaryOperator<U> operator) {
>      return map(new Mapper<U,U>() {
>          private Object accumulator = NO_VALUE;
>
>          @Override
>          public U map(U element) {
>              Object acc = accumulator;
>              if (acc == NO_VALUE) {
>                  return element;
>              }
>              acc = operator.operate((U)acc, element);
>              accumulator = acc;
>              return (U)acc;
>          }
>      });
>   }


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