Trying to create an accumulator for a list, for example
public List<Double> accumulator(List<Double> originalList){
List result = new ArrayList<>();
Iterator<Double> iterator = originalList.iterator();
double sum = 0;
while(iterator.hasNext()){
sum = iterator.next() + sum;
result.add(sum);
}
return result;
}
Im trying to convert this into using Streams API, the only way i can think is starting by doing some partition and than sum the results.
input [20,15,25]
partitions:
[20] = 20
[20,15] = 35
[20,15,25] = 60
final result: [20,35,60]
Any insights?