Remote / Totals over a loaded list
The six kinds, and what each gives
| Aggregate | value | When the list has no rows |
|---|---|---|
Rows.sum(Row, $ => $.cents) | a number | 0 |
Rows.count(Row) | a number | 0 |
Rows.min(Row, $ => $.due) | an Option of a number | Option.none() |
Rows.max(Row, $ => $.due) | an Option of a number | Option.none() |
Rows.every(Row, $ => …) | a boolean | true |
Rows.any(Row, $ => …) | a boolean | false |
Rows.count(Row, $ => …) counts only the rows a condition holds of. min and
max give Option.none() also when no row has a value.
Rows.sum takes only whole-number contributions (a Schema.Int, Money or
Decimal field, and +, -, * over them) and throws when you call
Rows.sum, not later, for anything else: adding and taking away decimals drifts, so a total kept by
differences would stop matching one added up afresh. min and max skip a
null; a condition that cannot be decided (it reads a null) counts as false.
Row may name fewer fields than the list selects, but not a field it does
not: an aggregate over tax on this list is a type error, since the list
never decodes one.