tuple-stream2
Merges multiple streams into an aligned tuple stream.
Example
var through = var TupleStream = // an object map of streams, but could also be an arrayvar stooges = before: through after: through stoogesbeforestoogesbeforestoogesbeforestoogesbefore stoogesafterstoogesafterstoogesafterstoogesafter { return !a ? 1 : !b ? -1 : aid - bid } var tuples = tuples // {before: {id: 1, name: "Moe" }, after: {id: 1, name: "Moe"} },// {before: {id: 3, name: "Larry"}, after: {id: 3, name: "Larry"}},// {before: {id: 2, name: "Shemp"} },// { after: {id: 4, name: "Curly"}}
API
TupleStream(streams, [options])
Returns a readable stream.
streams
is a required object or array of readable streams.
options
is an optional object that can contain the following key:
comparator
: an optional function used to sort streams. It follows the specification used for Array.prototype.sort, and defaults tofunction(){ return 0 }
.
The returned stream emits values with the same keys as streams
, but with stream data instead of streams for the values.