Last active
March 27, 2018 12:30
-
-
Save titouancreach/76424348c0afe90dc3ddbd76e7cacf3d to your computer and use it in GitHub Desktop.
compose function written in recursive
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
export function compose(...fns) { | |
if (fns.length === 0) { | |
return fns; | |
} | |
return value => { | |
const g = fnsAcc => { | |
if (fnsAcc.length === 1) { | |
return fnsAcc[0](value); | |
} | |
const [head, ...tail] = fnsAcc; | |
return head(g(tail)) | |
}; | |
return g(fns) | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment