reduce
signature: reduce(accumulator: function, seed: any): Observable
reduce(accumulator: function, seed: any): Observable
Reduces the values from source observable to a single value that's emitted when the source completes.
💡 Just like Array.prototype.reduce()
💡 If you need the current accumulated value on each emission, try scan!
Examples
Example 1: Sum a stream of numbers
( StackBlitz | jsBin | jsFiddle )
Additional Resources
reduce 📰 - Official docs
Scan() vs reduce() | RxJS TUTORIAL 🎥 - Academind
Build your own reduce operator 🎥 - Kwinten Pisman
📁 Source Code: https://github.com/ReactiveX/rxjs/blob/master/src/internal/operators/reduce.ts
Last updated