Member-only story
Functional Programming: Currying vs. Partial Application
What are they and how do we use them?
When learning functional programming, a lot of beginners get confused about some concepts of FP. When I was new to FP, I was so confused about currying and partial application.
In this post, I will talk about them with examples.
What Is Currying?
Well, mostly, if people get confused about this, then probably it would be because of the term curry which is the same as the food name from India.
However, in computer science, currying is a terminology of a technique. It has originated from a mathematical function.
Imagine there is a JavaScript function, add
.
const add = (x, y) => x + y;
So, add
takes two arguments — x
and y
, and returns a summed value. This function, add
, can be represented in a mathematical way as follows:
f(x,y) = x + y
Then, the function f(x,y)
can be represented like this:
f(x,y) = h(x)(y) = x + y
h
is a translated function that takes a single argument and outputs a function that takes a single argument. With x = 2
, then the function f
will be like this, below: