| 114 | } |
| 115 | |
| 116 | fn sum_datum<'a, I, DatumType, ResultType>(datums: I) -> Datum<'a> |
| 117 | where |
| 118 | I: IntoIterator<Item = Datum<'a>>, |
| 119 | DatumType: TryFrom<Datum<'a>>, |
| 120 | <DatumType as TryFrom<Datum<'a>>>::Error: std::fmt::Debug, |
| 121 | ResultType: From<DatumType> + Sum + Into<Datum<'a>>, |
| 122 | { |
| 123 | let mut datums = datums.into_iter().filter(|d| !d.is_null()).peekable(); |
| 124 | if datums.peek().is_none() { |
| 125 | Datum::Null |
| 126 | } else { |
| 127 | let x = datums |
| 128 | .map(|d| ResultType::from(DatumType::try_from(d).expect("unexpected type"))) |
| 129 | .sum::<ResultType>(); |
| 130 | x.into() |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | /// Count-aware signed-integer sum. Accumulates `Σ value·diff` in `i128`, which |
| 135 | /// matches the width of the dataflow's `Accum::SimpleNumber` accumulator (see |