Skip to content

Instantly share code, notes, and snippets.

@quieterkali
Created August 6, 2017 01:44
Show Gist options
  • Save quieterkali/eccf5aecdccad540ec226359354d7ace to your computer and use it in GitHub Desktop.
Save quieterkali/eccf5aecdccad540ec226359354d7ace to your computer and use it in GitHub Desktop.
custom curry funtion
const curry = (fn) => {
if(typeof fn !== 'function') {
throw Error('No function provided');
}
return function curriedFn(...args) {
if(args.length < fn.length) {
return function() {
return curriedFn.apply(null, args.concat([].slice.call(arguments)));
};
}
return fn.apply(null, args);
};
};
@quieterkali
Copy link
Author

quieterkali commented Aug 6, 2017

olha esse trecho:
if(args.length < fn.length) { return function() { return curriedFn.apply(null, args.concat([].slice.call(arguments))); }; }
porque nao simplesmente nao é:

`if(args.length < fn.length) {

  return curriedFn.apply(null, args.concat([].slice.call(arguments)));

}`

???

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment