Curry Functions in JavaScript
This is a series of articles on currying functions in JavaScript. It consists of an introductory post (this one) and several follow ups that delve into basic and advanced currying with JavaScript.
In the next post, named Basic Curried Functions in JavaScript, we’ll see an example of a basic curried function. And in the follow up posts, we’ll gradually cover more advanced techniques for currying existing functions.
Get Abdullah Numan’s stories in your inbox
Join Medium for free to get updates from this writer.
Before that, first, we’ll consider a few underlying terminologies.
Arity
The arity of a function is the number of arguments a function expects at invocation.
Unary Functions
Unary functions are functions that take only one argument, i.e. their arity is one. They are very common in Haskell, where a function can only be unary.
Curried Functions
The simplest form of a curried function is a unary function that returns another unary function. The returned function can also return another unary function. Returning nested unary functions continues in sequence to achieve the results of a multi-argument function. This gives us the ability to call the function with one argument at a time, sequentially.
// Regular multi-argument function
const createMessage = (greeting, name, message) => {
return `${greeting}, ${name}! ${message}`);
};
// A curried function helping achieve the same thing
const createMessage = greeting => name => message => `${greeting}, ${name}! ${message}`);
// So now we can do this:
createMessage('Hello')('World')('Whadup?');In Haskell, this is the technique used to deliver functions that effectively accept multiple arguments, but one at a time. The word “curry” comes from Haskell Curry.
Higher Order Functions
Curried functions are also Higher Order Functions, or HOFs — as they always return other functions, and also commonly take in the to-be-curried function.
Variadic Curried Functions
A variadic curried function is a more sophisticated curried function that is able to take variable number of arguments per call. Each returned function may take a single argument, or more than one argument. Basically, we can also do this:
createMessage(‘Hello’, ‘World’)(‘Whadup?’);
// or
createMessage(‘Hello’)(‘World’, ‘Whadup?’);





