Skip to content

Instantly share code, notes, and snippets.

@WaldoJeffers
Last active October 23, 2020 01:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WaldoJeffers/ebc37a2b81c148fcf2cd6b97eae254cb to your computer and use it in GitHub Desktop.
Save WaldoJeffers/ebc37a2b81c148fcf2cd6b97eae254cb to your computer and use it in GitHub Desktop.
JavaScript one-line curry (ES6)
const curry = (fn, arity = fn.length) => (...args) => args.length >= arity ? fn(...args) : (...moreArgs) => curry(fn)(...args, ...moreArgs)
// tests
const _add = (a, b, c) => a + b + c
describe('curry', () => {
it('should currify the input function', () => {
const add = curry(_add)
expect(add(1, 2, 3)).toBe(6)
expect(add(1)(2)(3)).toBe(6)
expect(add(1, 2)(3)).toBe(6)
expect(add(1)(2, 3)).toBe(6)
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment