foldRightIndexed<S> method
Null safety
- S initial,
- IndexedReversedAccumulate<
S, E> f
Accumulates a collection to a single value, which starts from an initial
value,
by combining each element with the current accumulator value,
with the combinator f
in a reversed order, providing sequential index of the element.
It's the index-aware version of foldRight()
.
Caution: to reverse an Iterable
may cause performance issue, see sdk#26928
Implementation
S foldRightIndexed<S>(S initial, IndexedReversedAccumulate<S, E> f) {
final list = asList();
final len = list.length;
var acc = initial;
for (var i = len - 1; i >= 0; i--) {
acc = f(i, list[i], acc);
}
return acc;
}