reduce<T, R> function
R
reduce<T, R>()
Applies reducer against an accumulator initialized to initialValue and
each element of values to reduce it to a single value of type R.
Implementation
// DIVERGES(d3-array): adapt-array-typed-api, split typed reduce (with
// initialValue) and reduceFirst (without initialValue, returning T?).
R reduce<T, R>(
Iterable<T> values,
R Function(R accumulator, T value, int index, Iterable<T> values) reducer,
R initialValue,
) {
var value = initialValue;
var index = -1;
for (final next in values) {
value = reducer(value, next, ++index, values);
}
return value;
}