reduce<S> method
S
reduce<S>(
- S operation(
- S acc,
- T
Accumulates value starting with the first element and applying operation
from left to right to current accumulator value and each element.
Implementation
S reduce<S>(S Function(S acc, T) operation) {
final i = iterator();
if (!i.hasNext()) {
throw UnsupportedError("Empty collection can't be reduced.");
}
S accumulator = i.next() as S;
while (i.hasNext()) {
accumulator = operation(accumulator, i.next());
}
return accumulator;
}