Skip to content

Instantly share code, notes, and snippets.

@literadix
Forked from alanmquach/RxZipper.js
Created November 25, 2015 12:59
Show Gist options
  • Save literadix/a05409bf9e29bc5fa03a to your computer and use it in GitHub Desktop.
Save literadix/a05409bf9e29bc5fa03a 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);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment