reduceRightIndexed<S> method
Accumulates value starting with last element and applying operation
from right to left
to each element with its index in the original list and current accumulator value.
@param operation
function that takes the index of an element, the element itself
and current accumulator value, and calculates the next accumulator value.
Implementation
S reduceRightIndexed<S>(S Function(int index, 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.previousIndex(), i.previous(), accumulator);
}
return accumulator;
}