Skip to content

Instantly share code, notes, and snippets.

Last active September 19, 2020 20:41
  • Star 11 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
ES6 Partial Application in 3 Lines

ES6 Partial Application in 3 Lines

const pApply = (fn, ...cache) => (...args) => {
  const all = cache.concat(args);
  return all.length >= fn.length ? fn(...all) : pApply(fn, ...all);


Create a function like so:

const add = pApply((a, b, c) => a + b + c);

Use it as follows:

// => function
add(1, 2);
// => function
add(1, 2, 3);
// => 6
// => 6
Copy link

farskid commented Jan 4, 2018

Great approach! A tiny issue though:
according to this great article by Eric Elliot , this could be named as ES6 partial applied function rather that curried. Curry is supposed to point to a function that is accepting it's collection of arguments in a series of calls, each accepting only 1 parameter!

Copy link

Thanks a lot @farskid, fixed!

Copy link

lihaibh commented Apr 6, 2018

Great simple way to make curried functions.
Reminds me the library ramdajs you can do: R.curry(fn); and get partial unfullfiled function

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment