Skip to content

Instantly share code, notes, and snippets.

@MiguelCastillo
Created September 16, 2016 16:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MiguelCastillo/52ff4bd429facca52b336f9beda27c27 to your computer and use it in GitHub Desktop.
Save MiguelCastillo/52ff4bd429facca52b336f9beda27c27 to your computer and use it in GitHub Desktop.
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