Skip to content

Instantly share code, notes, and snippets.

@kucherenko
Created January 13, 2021 11:20
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 kucherenko/2a687f15d6d35f2455d2720a660d754b to your computer and use it in GitHub Desktop.
Save kucherenko/2a687f15d6d35f2455d2720a660d754b to your computer and use it in GitHub Desktop.
const curry = (fn, ...args) => {
return fn.length <= args.length ? fn(...args) : curry.bind(null, fn, ...args);
}
// Example
const sum = (a, b, c) => a + b + c;
curry(sum)(3)(4)(5); // 12
curry(sum)(3, 4, 5); // 12
curry(sum, 3)(4, 5); // 12
curry(sum, 3)(4)(5); // 12
curry(sum, 3, 4)(5); // 12
curry(sum, 3, 4, 5); // 12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment