foldRight<R> method

R foldRight<R>(
  1. R initial,
  2. R operation(
    1. T,
    2. R acc
    )
)

Accumulates value starting with initial value and applying operation from right to left to each element and current accumulator value.

Implementation

R foldRight<R>(R initial, R Function(T, R acc) operation) {
  if (isEmpty()) return initial;

  var accumulator = initial;
  final i = listIterator(size);
  while (i.hasPrevious()) {
    accumulator = operation(i.previous(), accumulator);
  }
  return accumulator;
}