reduceIndexedOrNull method

E? reduceIndexedOrNull(
  1. E combine(
    1. int index,
    2. E value,
    3. E element
    )
)

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

Implementation

E? reduceIndexedOrNull(E Function(int index, E value, E element) combine) {
  if (isEmpty) return null;

  final iterator = this.iterator..moveNext();
  int index = 1;
  E value = iterator.current;

  while (iterator.moveNext()) {
    value = combine(index++, value, iterator.current);
  }

  return value;
}