foldIndexed<R> method Null safety

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

Combine the elements with a value and the current index.

Calls combine for each element with the current index, the result of the previous call, or initialValue for the first element, and the current element.

Returns the result of the last call to combine, or initialValue if there are no elements.

Implementation

R foldIndexed<R>(
    R initialValue, R Function(int index, R previous, T element) combine) {
  var result = initialValue;
  var index = 0;
  for (var element in this) {
    result = combine(index++, result, element);
  }
  return result;
}