package com.wizzardo.tools.collections.flow.flows;

import com.wizzardo.tools.collections.flow.Reducer;

/**
 * Created by wizzardo on 16.04.16.
 */
public class FlowReduce<T> extends FlowProcessOnEnd<T, T> {
    private final Reducer<T> reducer;
    private T prev;

    public FlowReduce(T def, Reducer<T> reducer) {
        this.reducer = reducer;
        prev = def;
    }

    @Override
    public void process(T t) {
        T prev = this.prev;
        if (prev == null)
            this.prev = t;
        else
            this.prev = reducer.reduce(prev, t);
    }

    @Override
    public T get() {
        return prev;
    }
}

@@ -243,28 +243,8 @@
 cer;
-%0A    private T prev;
 %0A%0A  
@@ -332,20 +332,22 @@
         
-p
 re
-v
+sult
  = def;%0A
@@ -420,20 +420,22 @@
  = this.
-p
 re
-v
+sult
 ;%0A      
@@ -471,20 +471,22 @@
    this.
-p
 re
-v
+sult
  = t;%0A  
@@ -513,20 +513,22 @@
    this.
-p
 re
-v
+sult
  = reduc
@@ -556,70 +556,7 @@
    %7D
-%0A%0A    @Override%0A    public T get() %7B%0A        return prev;%0A    %7D
 %0A%7D%0A

update 'reduce'