foldRightIndexed<R> method
Accumulates value starting with initial
value 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
R foldRightIndexed<R>(R initial, R Function(int index, T, R acc) operation) {
if (isEmpty()) return initial;
var accumulator = initial;
final i = listIterator(size);
while (i.hasPrevious()) {
accumulator = operation(i.previousIndex(), i.previous(), accumulator);
}
return accumulator;
}