Skip to content

Instantly share code, notes, and snippets.

@GianlucaGuarini
Last active November 18, 2017 21:55
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 GianlucaGuarini/e4acc089587576f8d6205e8057b29d09 to your computer and use it in GitHub Desktop.
Save GianlucaGuarini/e4acc089587576f8d6205e8057b29d09 to your computer and use it in GitHub Desktop.
Function to curry any javascript method
/**
* Function to curry any javascript method
* @param {Function} fn - the target function we want to curry
* @param {...[args]} acc - initial arguments
* @returns {Function|*} it will return a function until the target function
* will receive all its arguments
*/
function curry(fn, ...acc) {
return (...args) => {
args = [...acc, ...args]
return args.length < fn.length ?
curry(fn, ...args) :
fn(...args)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment