Glossary

Currying

Currying is a functional programming technique: transforming a function with N arguments into a sequence of functions each taking one argument. Enables partial application and the creation of specialised functions.

The idea

// Regular function
add(2, 3) → 5

// Curried
add(2)(3) → 5

// Partially applied
addTwo = add(2)
addTwo(3) → 5
addTwo(10) → 12

PHP example

$multiply = fn($a) => fn($b) => $a * $b;

$double  = $multiply(2);
$triple  = $multiply(3);

echo $double(5);  // 10
echo $triple(5);  // 15

// Pipeline
$result = array_map($double, [1, 2, 3, 4]);
// [2, 4, 6, 8]

Practical value

Currying is rarely used directly in PHP, but the concept of partial application is useful for building pipelines, configuring functions, and callbacks. In JavaScript and Haskell it is far more widespread.