What is the advantage of Currying in C#?
What is the advantage of achieving partial function application on a curried function?
From Wikipedia
Currying is actually not very different from what we do when we calculate a function for some given values on a piece of paper.
Take the function
f(x,y) = y / x
To evaluate
f(2,3)
, first, replacex
with2
.Since the result is a new function in y, this function g(y) can be defined as
g(y) = f(2,y) = y / 2
Next, replacing the
y
argument with3
,provides the result,
g(3) = f(2,3) = 3 / 2
.On paper, using classical notation, it's just that we seem to do it all at the same time. But, in fact, when replacing arguments on a piece of paper, it is done sequentially (i.e.partially). Each replacement results in a function within a function. As we sequentially replace each argument, we are currying the function into simpler and simpler versions of the original. Eventually, we end up with a chain of functions as in lambda calculus, where each function takes only one argument, and multi-argument functions are usually represented in curried form.
The practical motivation for currying is that very often the functions obtained by supplying some but not all of the arguments to a curried function (often called partial application) are useful; for example, many languages have a function or operator similar to plus_one. Currying makes it easy to define these functions.