Last active
October 25, 2016 01:42
-
-
Save ybouhjira/0d6061af168005793ed6517f1aaf2c47 to your computer and use it in GitHub Desktop.
Distribute stream on an other stream
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
console.clear(); | |
const items$ = Rx.Observable | |
.interval(100) | |
.map(x => `item-${x}`) | |
.take(100) | |
.share(); | |
const cc$ = Rx.Observable | |
.interval(0) | |
.take(2) | |
.scan(count => count + 1, 0) | |
.share(); | |
const zip$ = Rx.Observable | |
.zip( | |
items$, | |
items$.scan(count => count + 1, 0) | |
); | |
Rx.Observable | |
.combineLatest(zip$, cc$, (z, cc) => { | |
return [z[0], z[1], cc]; | |
}) | |
//.subscribe(x => console.log(x)); | |
.groupBy(([i, c, cc]) => c % cc) | |
.flatMap(x => x) | |
.subscribe(x => console.log(x)); |
Author
ybouhjira
commented
Oct 25, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment