Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Reactive Programming, medium, sum-example-reactive-working
const Rx = require('rxjs');
const n$ = new Rx.Observable((observer) => {
observer.next(2);
setTimeout(() => {
observer.next(3);
observer.complete();
}, 200);
});
const m$ = Rx.Observable.of(3);
const sum = (acc, x) => acc + x;
const t$ = n$.mergeMap(n =>
Rx.Observable.of(n)
.concat(m$)
.reduce(sum)
);
t$.subscribe(t => {
console.log(`Result: ${t}`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.