Skip to content

Instantly share code, notes, and snippets.

@ashish173
Created December 8, 2016 21:38
Show Gist options
  • Save ashish173/79f15f678b089b7f194c4d78a0935d14 to your computer and use it in GitHub Desktop.
Save ashish173/79f15f678b089b7f194c4d78a0935d14 to your computer and use it in GitHub Desktop.
FlatMap
var source = Rx.Observable
.range(1, 2)
.flatMap(function (x) {
return Rx.Observable.range(x, 2);
});
var subscription = source.subscribe(
function (x) { console.log('Next: ' + x); },
function (err) { console.log('Error: ' + err); },
function () { console.log('Completed'); });
// Next: 1, 2, 2, 3
// when 1 from outer observable is passed in it results into 1, 2
// when 2 from outer observable is passed in it results into 2, 3
// All the results matter here from the source unlike switchMap.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment