Created
October 24, 2016 02:00
-
-
Save ybouhjira/bc47fdfb53a78fc3ab1302cebb3009cb 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, | |
([i, c, cc]) => ([i, c, c % cc]) | |
) | |
.flatMap(x => x) | |
.subscribe(x => console.log(x)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment