Last active
August 10, 2016 09:04
-
-
Save fayesafe/497456de24b3a64d4ca6d51f1132a0f1 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
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