Skip to content

Instantly share code, notes, and snippets.

@ortense
Last active August 5, 2017 19:43
Show Gist options
  • Save ortense/6fcee8dd458ec7137db5bc824ab30f8f to your computer and use it in GitHub Desktop.
Save ortense/6fcee8dd458ec7137db5bc824ab30f8f to your computer and use it in GitHub Desktop.
simple and small curry function
const curry = (fn, ...args) => {
if (args.length === fn.length) return fn(...args)
return (...more) => curry(fn, ...args, ...more)
}
/*
const add = (a, b, c) => a + b + c
const curred = curry(add)
console.log(add(1,2,3)) // 6
console.log(curred(1)) // (b, c) => 1 + b + c
console.log(curred(1,2)) // (c) => 1 + 2 + c
console.log(curred(1,2,3)) // 6
console.log(curred(1)(2,3)) // 6
console.log(curred(1,2)(3)) // 6
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment