Created
February 7, 2018 05:43
-
-
Save joe-crick/3066d232cf22ab513750d54e6a060df8 to your computer and use it in GitHub Desktop.
JS Curry Example
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
// A sample Currying function | |
const partial = (f, ...as) => { | |
if (as.length === 0) { return f.call(); } | |
const a = as.shift(); | |
if (a === undefined) { return f; } | |
const p = f.bind(f, a); | |
return partial(p, ...as); | |
} | |
// Composition function | |
const $ = f => (g, x) => x === undefined ? x => f(g(x)) : f(g(x)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment