foldIndexed<T> method

T foldIndexed<T>(
  1. T initialValue,
  2. T combine(
    1. int index,
    2. T previousValue,
    3. E element
    )
)

Accumulates value starting with initialValue and applying operation from left to right to current accumulator value and each element with its index in the original collection.

Implementation

T foldIndexed<T>(
  T initialValue,
  T Function(int index, T previousValue, E element) combine,
) {
  var index = 0;
  return fold(
    initialValue,
    (previousValue, element) => combine(index++, previousValue, element),
  );
}