( valueExtractor: (value: T) => any = (v) => v, )
| 167 | * Creates a count aggregate function |
| 168 | */ |
| 169 | export function count<T>( |
| 170 | valueExtractor: (value: T) => any = (v) => v, |
| 171 | ): AggregateFunction<T, number, number> { |
| 172 | return { |
| 173 | // Count only not-null values (the `== null` comparison gives true for both null and undefined) |
| 174 | preMap: (data: T) => (valueExtractor(data) == null ? 0 : 1), |
| 175 | reduce: (values: Array<[number, number]>) => { |
| 176 | let totalCount = 0 |
| 177 | for (const [nullMultiplier, multiplicity] of values) { |
| 178 | totalCount += nullMultiplier * multiplicity |
| 179 | } |
| 180 | return totalCount |
| 181 | }, |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | /** |
| 186 | * Creates an average aggregate function |
nothing calls this directly
no test coverage detected