Skip to content

Instantly share code, notes, and snippets.

@jethrolarson
Last active April 15, 2016 21:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jethrolarson/ab4fd654b9a357cf0cced5315b4648a4 to your computer and use it in GitHub Desktop.
Save jethrolarson/ab4fd654b9a357cf0cced5315b4648a4 to your computer and use it in GitHub Desktop.
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