Remove cumulate from Stream interface

Remi Forax forax at univ-mlv.fr
Wed Dec 5 06:33:02 PST 2012


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