Skip to content

Instantly share code, notes, and snippets.

@airled
Last active March 2, 2023 15:08
Show Gist options
  • Select an option

  • Save airled/b8ca045171b136de16f939461f9d90b1 to your computer and use it in GitHub Desktop.

Select an option

Save airled/b8ca045171b136de16f939461f9d90b1 to your computer and use it in GitHub Desktop.
Simple currying example in JS
class Curry {
constructor(fn) {
return this.curry(fn, fn.length, [])
}
curry(fn, argRestCounter, args) {
if (argRestCounter === 0) return fn(…args);
return arg => this.curry(fn, argRestCounter — 1, […args, arg]);
}
}
const f = (x, y, z) => x * y + z;
const cur = new Curry(f);
cur(2)(3)(4) // 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment