foldRightIndexed<R> method

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

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

Implementation

R foldRightIndexed<R>(
  R initialValue,
  R Function(int index, R previousValue, E element) combine,
) {
  var index = length - 1;

  return reversed.fold(
    initialValue,
    (previousValue, element) => combine(index--, previousValue, element),
  );
}