Last active
April 28, 2018 11:25
-
-
Save nairihar/4d7d226eefc73d926ec3816295de4bb6 to your computer and use it in GitHub Desktop.
Reactive Programming, medium, sum-example-reactive-working
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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