runningFoldIndexed<R> method
Iterable<R>
runningFoldIndexed<R>(
- R initialValue,
- R combine(
- int index,
- R previousValue,
- E element
Returns a Iterable containing successive accumulation values generated
by applying combine
function from left to right to each element and
current accumulator value that starts with initialValue
.
Implementation
Iterable<R> runningFoldIndexed<R>(
R initialValue,
R Function(int index, R previousValue, E element) combine,
) {
var previousValue = initialValue;
return [initialValue].followedBy(withIndex.map((indexedValue) {
previousValue = combine(
indexedValue.index,
previousValue,
indexedValue.value,
);
return previousValue;
}));
}