reduceIndexedOrNull<S> method

S? reduceIndexedOrNull<S>(
  1. S operation(
    1. int index,
    2. S acc,
    3. T
    )
)

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

Returns null if the list is empty.

Implementation

S? reduceIndexedOrNull<S>(S Function(int index, S acc, T) operation) {
  final i = iterator();
  if (!i.hasNext()) {
    return null;
  }
  var index = 1;
  S accumulator = i.next() as S;
  while (i.hasNext()) {
    accumulator = operation(index++, accumulator, i.next());
  }
  return accumulator;
}