Currying a Function

Currying a function is essentially a function that returns back another function. The reason you do this is maybe function “curryFunc” receives some variable “a”. What happens is the return function might use “a” inside of it. But what it does is it depends on two additional properties that you add to it as new parameters for this function.

const curryFunc = (a) => (b, c) => {
a + b - c
}

const with3 = curryFunc(3);
const with10 = curryFunc(3);

with3(2, 4); // 3 + 2 - 4
with10(9, 2); // 3 + 9 - 2

The above example shows how you can create functions from a function (reusable functions).

This type of logic is very helpful when creating our own custom middleware functions for Redux.

Leave a Reply

Your email address will not be published. Required fields are marked *