Created
September 15, 2017 22:29
-
-
Save slugbyte/2b1e5ebde3214e3ec82566e08787cafc 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
let curry = (fn, ...defaults) => { | |
if(typeof fn !== 'function') throw new Error('Expected a function') | |
if(fn.length < 2) return fn | |
if(defaults.length >= fn.length) return fn(...defaults) | |
return (...args) => curry(fn, ...defaults.concat(args)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment