Function currying, or how to reduce n-ary functions to unary functions
Function currying is often mistaken for partial application. As you will see, function currying and partial application are related but not identical concepts. When we talk about function currying, we are talking about transforming a function that takes a single argument to a sequence of functions where each function takes exactly one argument. In pseudocode, what we are doing is transforming a function such as the following into a sequence of three functions:
func F(a,b,c): int {}
The first function, (Fa)
, takes the a
argument as input and returns a new function, (Fb)
, as output. (Fb)
takes b
as input and returns an (Fc)
function. (Fc)
, the final function, takes c
as input and returns an int
object as output:
func Fa(a): Fb(b) func Fb(b): Fc(c) func Fc(c): int
This is done by leveraging the concept of first-class citizens and higher-order functions once again. We’ll be able to achieve this transformation...