reduceRight<S> method

S reduceRight<S>(
  1. S operation(
    1. T,
    2. S acc
    )
)

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

Implementation

S reduceRight<S>(S Function(T, S acc) operation) {
  final i = listIterator(size);
  if (!i.hasPrevious()) {
    throw UnimplementedError("Empty list can't be reduced.");
  }
  var accumulator = i.previous() as S;
  while (i.hasPrevious()) {
    accumulator = operation(i.previous(), accumulator);
  }
  return accumulator;
}