signature: reduce(accumulator: function, seed: any): Observable

Reduces the values from source observable to a single value that's emitted when the source completes.

:bulb: Just like Array.prototype.reduce()

:bulb: If you need the current accumulated value on each emission, try scan!


Example 1: Sum a stream of numbers

( jsBin | jsFiddle )

const source = Rx.Observable.of(1, 2, 3, 4);
const example = source.reduce((acc, val) => acc + val);
//output: Sum: 10'
const subscribe = example.subscribe(val => console.log('Sum:', val));

Additional Resources

:file_folder: Source Code:

results matching ""

    No results matching ""