reduce method
Reduces the Map to a single key/value pair MapEntry by iteratively
combining combine
each entry
of the Map into an accumulator
.
The Map must have at least one key/value pair. If it has only one pair, that pair is returned.
Otherwise this method starts with the first pair from the Map iterator, and then combines it with the remaining pairs in iteration order.
Implementation
MapEntry<K, V> reduce(
MapEntry<K, V> Function(MapEntry<K, V> accumulator, MapEntry<K, V> entry)
combine,
) {
Iterator<MapEntry<K, V>> iterator = entries.iterator;
if (!iterator.moveNext()) throw ArgumentError('$this cannot be empty.');
var entry = iterator.current;
while (iterator.moveNext()) {
entry = combine(entry, iterator.current);
}
return entry;
}