Created
September 16, 2016 16:56
-
-
Save MiguelCastillo/52ff4bd429facca52b336f9beda27c27 to your computer and use it in GitHub Desktop.
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
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