Numbers\multiply()

transformer returns Closure pure throws
number → (number → number)
At a glance — Bind a factor up front; the returned Closure is a reusable multiplier. Result follows PHP's native arithmetic rules. Throws InvalidArgumentException on non-number input.

Creates a Closure that multiplies any number it receives by a pre-defined factor. Ideal for scaling values inside map/pipe chains.

/**
  * @param int|float $initial Defaults to 1.
  * @return Closure(int|float):(int|float)
  * @throws InvalidArgumentException If $initial is not int or float.
  */
Numbers\multiply($initial = 1): Closure

Returned Closure

When Numbers\multiply() is called, it returns the following Closure which can be used like a regular function.

/**
  * @param int|float $value
  * @return int|float  Result of ($value * $initial).
  */
$function (int|float $value): int|float

Examples

Partial Application

This can be used to create a simple closure which can be used as a regular function.

// Create a function that doubles anything it receives.
$double = Numbers\multiply(2);

// Called as a function.
echo $double(5);    // 10
echo $double(2.5);  // 5

// Used in a higher order function.
$array = array_map($double, [1, 2, 3, 4]);
print_r($array); // [2, 4, 6, 8]

Curried

This can be called inline using currying.

echo Numbers\multiply(10)(2.5); // 25

Inlined with Higher Order Function

If you are not planning on reusing the Closure created, you can just call it inline with a higher order function as its callable.

$array = array_map(Numbers\multiply(3), [1, 2, 3]);
print_r($array); // [3, 6, 9]

Details

Numbers Functions

Releated Number arithmetic Functions