Skip to content

Instantly share code, notes, and snippets.

@alanmquach
Last active November 25, 2015 12:59
Show Gist options
  • Save alanmquach/d5b43e1e925c26f85bc9 to your computer and use it in GitHub Desktop.
Save alanmquach/d5b43e1e925c26f85bc9 to your computer and use it in GitHub Desktop.
RxJS equivalent of async.parallel
var Rx = require('rx');
var zipper = function () {
// Turning arguments from an object into an actual array so we can use things like map()
return Array.prototype.slice.call(arguments);
};
var array; // Given some array of Observables that you want zipped together
// Or the more classical case where given an array of data to operate on, simply map them into observables
var data = [0, 1, 2, 3, 4, 5];
array = data.map(function (element) {
return Rx.Observable.create(function (observer) {
observer.onNext(element);
});
});
// After transforming
Rx.Observable.zip.apply(Rx.Observable, array.concat(zipper)).subscribe(function (zipped) {
// Yay! Zipped data!
console.log(zipped);
});
@rogeriochaves
Copy link

@alanmquach You may now simply use zipArray

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment