Created
March 12, 2012 17:02
-
-
Save cburgdorf/2023362 to your computer and use it in GitHub Desktop.
Bring back the forkJoin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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