March 2019
Intermediate to advanced
350 pages
7h 28m
English
A common technique in FP is currying. Currying is the process of converting a function that takes multiple arguments into a function that takes one argument at a time, returning another function. Let's look at an example to clarify the concept.
Let's start with the add function we have seen before and transform it into a curried function.
Instead of writing the following code:
const add = (x, y) => x + y;
We define the function as follows:
const add = x => y => x + y;
And we use it in the following way:
const add1 = add(1);add1(2); // 3add1(3); // 4
This is a pretty convenient way of writing functions because, since the first value is stored after the application of the first parameter, we can reuse the second function multiple ...
Read now
Unlock full access