Currying

Currying is a technique of translating the evaluation of a function that takes multiple arguments.

Ex:
// Basic
const multiply = (a, b) => a*b;
multiply(3, 4); // 12

// currying
const curriedMultiply = (a) => (b) => a * b;
curriedMultiply(3)(4); // 12

Currying is useful for creating multiple utility functions.

Ex:
const curriedMultiply = (a) => (b) => a * b;
const multiplyBy5 = curriedMultiply(5);
multiplyBy5(4) // 20

Instead of running the same code multiple times, i can now run the first part code once and second part code for usability times;

Last updated