Skip to content

Instantly share code, notes, and snippets.

@fayesafe
Last active August 10, 2016 09:04
Show Gist options
  • Save fayesafe/497456de24b3a64d4ca6d51f1132a0f1 to your computer and use it in GitHub Desktop.
Save fayesafe/497456de24b3a64d4ca6d51f1132a0f1 to your computer and use it in GitHub Desktop.
interface func {
(arg: any): any;
}
function compose(...funcs: func[]): func {
if (funcs.length === 1) {
return (arg: any) => funcs.shift()(arg);
} else if (funcs.length > 1) {
return (arg: any) => funcs.reduceRight((prev, item) => item(prev), arg);
} else {
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment