foldIndexed<R> method
- R initialValue,
- R combine(
- int index,
- R previous,
- T element
Combine the elements with a value and the current index.
Calls combine
for each element with the current index,
the result of the previous call, or initialValue
for the first element,
and the current element.
Returns the result of the last call to combine
,
or initialValue
if there are no elements.
Implementation
R foldIndexed<R>(
R initialValue, R Function(int index, R previous, T element) combine) {
var result = initialValue;
var index = 0;
for (var element in this) {
result = combine(index++, result, element);
}
return result;
}