Skip to content

Instantly share code, notes, and snippets.

@guz-anton
Last active October 30, 2018 16:07
Show Gist options
  • Save guz-anton/dc6f6dd5993290ba0dde094c10b175d5 to your computer and use it in GitHub Desktop.
Save guz-anton/dc6f6dd5993290ba0dde094c10b175d5 to your computer and use it in GitHub Desktop.
Redusing arguments
const curry = (fn, ...initialArgs) => {
let value;
const fnx = (...curryArgs) => {
value = fn.apply(null, initialArgs.concat(curryArgs));
return fnx;
}
Object.defineProperty(fnx, 'valueOf', {value: () => value});
return fnx;
}
const curry = (fn, ...initialArgs) => {
let value;
const fnx = (...curryArgs) => {
if(initialArgs.length || curryArgs.length) {
value = initialArgs.concat(curryArgs).reduce(fn);
}
return fnx;
}
Object.defineProperty(fnx, 'valueOf', {value: () => value});
return fnx();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment