aggregateByKeys<T, R> function
Groups items by keys and reduces each bucket with aggregator,
returning a map from composite key to the aggregate (e.g. a count, sum, or
average per (country, year)).
Example:
aggregateByKeys(rows, [(r) => r['country']], (g) => g.length); // count
Audited: 2026-06-12 11:26 EDT
Implementation
Map<MultiKey, R> aggregateByKeys<T, R>(
Iterable<T> items,
List<Object? Function(T)> keys,
R Function(List<T> group) aggregator,
) => groupByKeys(items, keys).map(
(MultiKey key, List<T> group) => MapEntry<MultiKey, R>(key, aggregator(group)),
);