Last active
August 5, 2017 19:43
-
-
Save ortense/6fcee8dd458ec7137db5bc824ab30f8f to your computer and use it in GitHub Desktop.
simple and small curry function
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 curry = (fn, ...args) => { | |
if (args.length === fn.length) return fn(...args) | |
return (...more) => curry(fn, ...args, ...more) | |
} | |
/* | |
const add = (a, b, c) => a + b + c | |
const curred = curry(add) | |
console.log(add(1,2,3)) // 6 | |
console.log(curred(1)) // (b, c) => 1 + b + c | |
console.log(curred(1,2)) // (c) => 1 + 2 + c | |
console.log(curred(1,2,3)) // 6 | |
console.log(curred(1)(2,3)) // 6 | |
console.log(curred(1,2)(3)) // 6 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment