runningReduceIndexed method

Iterable<E> runningReduceIndexed(
  1. E combine(
    1. int index,
    2. E value,
    3. E element
    )
)

Returns a Iterable containing successive accumulation values generated by applying combine function from left to right to each element, its index in the original collection and current accumulator value that starts with the first element of this collection.

Implementation

Iterable<E> runningReduceIndexed(
  E Function(int index, E value, E element) combine,
) {
  if (isEmpty) return Iterable.empty();

  var value = first;

  return withIndex.skip(1).map((indexedValue) {
    value = combine(indexedValue.index, value, indexedValue.value);
    return value;
  });
}