Currying
We already mentioned currying back in the Arrow functions section of Chapter 1, Becoming Functional, and in the One argument or many? section of Chapter 3, Starting Out with Functions, but let’s be more thorough here. Currying is a technique that enables you to only work with single-variable functions, even if you need a multi-variable one.
Currying by any other name?
The idea of converting a multi-variable function into a series of single-variable functions (or, more rigorously, reducing operators with several operands to a sequence of applications of a single operand operator) was worked on by Moses Schönfinkel. Some authors suggest, not necessarily tongue-in-cheek, that currying would be more correctly named Schönfinkeling!
In the following sections, we will first see how to deal with functions with many parameters, and then move on to how to curry by hand or by using bind()
.
Dealing with many parameters
The idea of currying, by itself, is...