stats/grouped_stats_utils library

Per-key descriptive statistics over an iterable — roadmap #571.

Where aggregateByKeys (collections) takes a custom reducer, this computes the common numeric bundle — count, sum, min, max, mean — for every group in a single pass. The frequent "totals and averages per category" report without writing the reducer each time.

Classes

NumericStats
Descriptive statistics for one group of numeric values.

Functions

groupedStats<T, K>(Iterable<T> items, {required K keyOf(T), required num valueOf(T)}) Map<K, NumericStats>
Groups items by keyOf and computes a NumericStats bundle over valueOf for each group, in a single pass. A key appears only if at least one item maps to it, so every returned NumericStats has count ≥ 1 (no divide-by-zero in mean). Insertion order of first-seen keys is preserved.