Skip to content

Instantly share code, notes, and snippets.

@cburgdorf
Created March 12, 2012 17:02
Show Gist options
  • Save cburgdorf/2023362 to your computer and use it in GitHub Desktop.
Save cburgdorf/2023362 to your computer and use it in GitHub Desktop.
Bring back the forkJoin
Rx.Observable.forkJoin = function (sources) {
var tempSources = arguments.length > 1 ? arguments : sources;
return Rx.Observable
.fromArray(tempSources)
.selectMany(function (o, i) {
return o.takeLast(1).select(function (value) { return { i: i, value: value }; });
})
.aggregate({ array: [], count: 0 }, function (results, result) {
results.array[result.i] = result.value;
return {
array: results.array,
count: results.count + 1
};
})
.where(function (results) { return results.count === tempSources.length; })
.select(function (results) { return results.array; });
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment