Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function streamChain(seed) {
var accumulator = [];
var streamFacade = {
write: function() {
throw new TypeError("This is not a stream. Please call sequence or parallel to get a stream out of this.");
},
pipe: function(stream) {
if (!seed) {
seed = stream;
}
else {
accumulator.push(stream);
}
return streamFacade;
},
parallel: function() {
accumulator.reduce(function(current, next) {
current.pipe(next);
return current;
}, seed);
return seed;
},
sequence: function() {
accumulator.reduce(function(current, next) {
current.pipe(next);
return next;
}, seed);
return seed;
}
};
return streamFacade;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.