Last active
September 25, 2018 12:31
-
-
Save paolobueno/f5b439dcd8b7968d374ad6cc553f31e1 to your computer and use it in GitHub Desktop.
Simple variadic compose
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
const apply = (x, fn) => fn(x); | |
const c = (...fns) => { | |
[first, ...rest] = fns.reverse(); | |
return x => rest.reduce(apply, first(x)); | |
} | |
const add = x => y => x + y; | |
c(add(1), add(4))(3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment