Last active
April 15, 2016 21:33
-
-
Save jethrolarson/ab4fd654b9a357cf0cced5315b4648a4 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
const curryHandler = boundArgs => ({ | |
apply: (target, thisArg, argList) => { | |
const totalArgs = boundArgs.concat(argList); | |
return totalArgs.length >= target.length ? | |
target.apply(thisArg, totalArgs) : new Proxy(target, curryHandler(totalArgs)); | |
}, | |
get: (target, prop) => | |
prop === 'length' ? | |
target.length - boundArgs.length : | |
prop === 'name' ? | |
target.name : | |
target[prop] | |
}); | |
//:: (* -> a) → (* -> a) | |
export const curry = fn => | |
new Proxy(fn, curryHandler([])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment