Curry or Partial Application?

The Difference Between
Partial Application and Curry

Eric Elliott
Jul 20, 2015 · 4 min read

A lot of people new to functional programming get confused about the difference between partial application and currying. In fact, until recently it was rare to see real uses of curry in JavaScript, and many of the utility functions calling themselves `curry()` weren’t curry functions at all. They were partial application functions!

If you’re confused about the difference, the following should clear it up for you, but first, let’s get some vocabulary out of the way:

Definitions

The process of applying a function to its arguments in order to produce a return value.

The process of applying a function to some of its arguments. The partially applied function gets returned for later use. In other words, a function that and Partial application fixes (partially applies the function to) one or more arguments inside the returned function, and the returned function takes the remaining parameters as arguments in order to complete the function application.

A function that as input and .

Why Does this Matter?

James Coglan gave a great talk that will help explain why you should care:

The features James talked about depend on function type uniformity. Functions have types. For instance, a function that takes a function and an array and returns an array (e.g. Function.prototype.map()):

(fn, array) -> array
  • A partial application .
  • A curried function always returns another function with an arity of 1 until all of the arguments have been applied.

All the cool things James talks about rely on For example he talks about how promises can help abstract your program logic’s dependence on time.

Promises do that because they whatever function you’re calling so that the return type is always uniform: All functions that return promises return the same type, which means that you can use them in standardized ways. James talks about lots of ways that promises help.

In this case, promises are containers which, like (a fancy word that basically means “something that can be mapped over”, e.g., an array. see also: ), can provide a standardized way to process the data inside the container regardless of the data’s type.

googling functional programming terms can be intimidating — it’s all a lot easier than academics make it sound.

By dealing with instead of the , you can create lots of generic for anything that uses the .

Like promises, that all share the same interface. The in this case. You just keep calling the returned function until you’ve exhausted all the arguments and the final value gets returned.

In other words, so that you can deal with those arguments in a standardized way.

The most common use-case for that kind of lifting is function composition, e.g., c(x) = f(g(x)). Function composition takes the return value of one function and feeds it in as an argument to another function. Since a function can only return one value, the function being applied to the return value must be unary.

Additionally, : A curried function will partially apply one argument at a time, never doing more work than it can do with a single argument. Calling the returned function has the effect of telling the function to apply the next step in the application.

For example, the curried function a(b)(c); doesn’t have to invoke the c application right away. It could be broken up like this:

const next = a(b);
doSomeStuff().then(() => next(c));

You should have a clearer understanding of the difference between partial application and curry, and why you’d want to curry your functions.

The most common use for currying in functional programming is to make it easier to compose functions. For more on that topic, read “Master the JavaScript Interview: What is Function Composition?”



is the author of “Programming JavaScript Applications” (O’Reilly), and “Learn JavaScript Universal App Development with Node, ES6, & React”. He has contributed to software experiences for , ,, , , and top recording artists including , , , and many more.

He spends most of his time in the San Francisco Bay Area with the most beautiful woman in the world.

JavaScript Scene

JavaScript, software leadership, software development, and…

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store