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);


Output

8

Difference Between Partial Application and Currying in javascript

Similar Reads

Partial Application

Partial Application is a technique used to fix or ‘partially’ apply some of the arguments of a function, creating a new function that expects the remaining arguments. This simplifies function calls and provides greater flexibility, making it easier to reuse and customize functions for specific use cases....

Currying

...

Difference Between Partial Application and Currying in javascript:

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....