Calculates the sum of all items in an Observable.
Observable
sum([initialState={total: 0}])
0.5
None
initialState: Object {total: Number}: Sets a warm startarrow-up-right value so that the calculation can continue from a non-zero starting point (instead of a blank state).
initialState: Object {total: Number}
Number. (The current sum of the Observable.)
Number
Last updated 6 years ago
import { from } from 'rxjs'; import { sum } from '@buccaneer/rxjs-stats'; const num$ = from([1, 2, 3, 4, 5]); const sum$ = num$.pipe( sum() ); num$.subscribe(console.log); // Output: // 1 // 3 // 6 // 10 // 15