Currying
Currying is a specialized technique related to partial application. It involves transforming a function that accepts multiple arguments into a series of unary functions. Each unary function takes one argument and returns another unary function. This process continues iteratively until all the original function’s arguments are processed. The Currying is particularly useful in functional programming for creating more modular and reusable code, as it allows for the step-by-step application of arguments, making it easier to compose and customize functions.
Example: In this example, we create a curried function curryAdd to add two numbers and provide the arguments step by step and we achieve partial application through currying.
Javascript
function GFG(x) { return function (y) { return x + y; }; } const add = GFG(5)(3); // Partial application using currying console.log(add); |
8