Skip to content

Instantly share code, notes, and snippets.

@ardeshireshghi
Last active March 16, 2017 12:12
Show Gist options
  • Save ardeshireshghi/fa046cdea3f66e2a3e600d33825489b4 to your computer and use it in GitHub Desktop.
Save ardeshireshghi/fa046cdea3f66e2a3e600d33825489b4 to your computer and use it in GitHub Desktop.
function pipelineOld() {
var args = [].slice.call(arguments);
var fns = (Array.isArray(args[0])) ? args[0] : args;
return function() {
var memo = arguments[0];
fns.forEach(function(fn) {
memo = fn(memo);
});
return memo;
};
}
/**
* More than 20% faster than `pipeline`
*/
function pipeline(...args) {
const fns = (Array.isArray(args[0])) ? args[0] : args;
const composedFn = (seed) => {
return fns.reduce((result, fn) => fn(result), seed);
};
return composedFn;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment