foldWithNext<V> method
V
foldWithNext<V>(
- V initialValue,
- V combiner(
- V previousValue,
- E current,
- E next
Reduces a collection to a single value by iteratively combining previous and current element of the collection with an existing value
Implementation
V foldWithNext<V>(V initialValue, V Function(V previousValue, E current, E next) combiner) {
Iterator<E> iterator = this.iterator;
if (!iterator.moveNext()) {
throw StateError("No element");
}
var value = initialValue;
E current = iterator.current;
while (iterator.moveNext()) {
value = combiner(value, current, iterator.current);
current = iterator.current;
}
return value;
}