Skip to content

Instantly share code, notes, and snippets.

@nicowernli
Last active March 23, 2018 11:54
Show Gist options
  • Save nicowernli/b85b2854400a98b4b72b81dedc967a94 to your computer and use it in GitHub Desktop.
Save nicowernli/b85b2854400a98b4b72b81dedc967a94 to your computer and use it in GitHub Desktop.
Medium flatMap example
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