Created
September 28, 2017 01:27
-
-
Save medric/04b7a4ff2f4ff344d05f9171b70026c4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| /** | |
| * Turns a group of functions into one unique callable function | |
| */ | |
| function compose(...funcs) { | |
| const length = funcs.length; | |
| if (length === 0) { | |
| return arg => arg | |
| } | |
| if (length === 1) { | |
| return funcs[0]; | |
| } | |
| return funcs.reduce((a, b) => (...args) => a(b(...args))); | |
| } | |
| export default compose; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment