computeAggregates<T> function

AggregateResult computeAggregates<T>(
  1. List<T> rows,
  2. List<Aggregation> aggregations,
  3. Object? read(
    1. T row,
    2. String field
    )
)

Runs every aggregation in aggregations over rows.

Implementation

AggregateResult computeAggregates<T>(
  List<T> rows,
  List<Aggregation> aggregations,
  Object? Function(T row, String field) read,
) {
  if (aggregations.isEmpty) return const AggregateResult.empty();
  final out = <String, Object?>{};
  for (final aggregation in aggregations) {
    out[aggregation.id] = aggregation
        .apply([for (final row in rows) read(row, aggregation.field)]);
  }
  return AggregateResult(out);
}