Skip to content

Instantly share code, notes, and snippets.

@ybouhjira
Created October 24, 2016 02:00
Show Gist options
  • Save ybouhjira/bc47fdfb53a78fc3ab1302cebb3009cb to your computer and use it in GitHub Desktop.
Save ybouhjira/bc47fdfb53a78fc3ab1302cebb3009cb to your computer and use it in GitHub Desktop.
Distribute stream on an other stream
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