@epikodelabs/streamix / aggregates/src/public-api / sum
Function: sum()
sum<
T>(selector?):Operator<T,number>
Defined in: projects/libraries/streamix/aggregates/src/lib/operators/sum.ts:15
Creates a stream operator that sums values from the source stream.
The operator consumes every value, optionally transforms it through the provided selector, and accumulates the sum. After the source completes, it emits the final total and completes. When there are no values, it emits 0.
Type Parameters
T
T = any
The type of the values in the source stream.
Parameters
selector?
(value, index) => MaybePromise<number>
Optional function that maps each value into a number. It receives the value and its index, and can be synchronous or asynchronous. Defaults to treating each value as a number directly.
Returns
Operator<T, number>
An Operator instance that can be used in a stream's pipe method.