Skip to content

Instantly share code, notes, and snippets.

@euhmeuh
Created October 17, 2018 09:20
Show Gist options
  • Save euhmeuh/29d831307371febfecaf4fb6416b8372 to your computer and use it in GitHub Desktop.
Save euhmeuh/29d831307371febfecaf4fb6416b8372 to your computer and use it in GitHub Desktop.
Javascript composition
function sequence() {
const funcs = arguments;
return function(x) {
return Array.from(funcs).reduce((x, func) => func.call(null, x), x);
};
}
function compose() {
return sequence.apply(null, Array.from(arguments).reverse());
}
const doIt = compose(
str => str+"!",
str => str.toUpperCase(),
str => str+"world",
);
console.log(doIt("hello"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment