Remove cumulate from Stream interface
Remi Forax
forax at univ-mlv.fr
Wed Dec 5 10:47:32 PST 2012
On 12/05/2012 04:05 PM, Brian Goetz wrote:
> Only if you don't care about parallel,
damn it, my cover is ruined :)
> 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.
Do you really want this overly restrictive wording for streams that are
sequential ?
I find this unrealistic, even if you try to specify this in the doc,
nobody read the doc if not forced.
Given that will not be enforced in the code, it will be only true on the
paper.
Rémi
>
> 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