foldIndexed<T> method
Accumulates value starting with initialValue
and applying operation from
left to right to current accumulator value and each element with its index
in the original collection.
Implementation
T foldIndexed<T>(
T initialValue,
T Function(int index, T previousValue, E element) combine,
) {
var index = 0;
return fold(
initialValue,
(previousValue, element) => combine(index++, previousValue, element),
);
}