Last active
March 23, 2018 11:54
-
-
Save nicowernli/b85b2854400a98b4b72b81dedc967a94 to your computer and use it in GitHub Desktop.
Medium flatMap example
This file contains hidden or 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 long$ = Rx.Observable.interval(1000).take(4); | |
const short$ = Rx.Observable.interval(500).take(4); | |
long$ | |
.flatMap(long => short$.map(short => console.log({ long, short }))) | |
.subscribe(); | |
/** Output | |
{ long: 0, short: 0 } | |
{ long: 0, short: 1 } | |
{ long: 1, short: 0 } | |
{ long: 0, short: 2 } | |
{ long: 1, short: 1 } | |
{ long: 0, short: 3 } | |
{ long: 2, short: 0 } | |
{ long: 1, short: 2 } | |
{ long: 2, short: 1 } | |
{ long: 1, short: 3 } | |
{ long: 3, short: 0 } | |
{ long: 2, short: 2 } | |
{ long: 3, short: 1 } | |
{ long: 2, short: 3 } | |
{ long: 3, short: 2 } | |
{ long: 3, short: 3 } | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment