dividend / value. Use divideBy() for the reverse direction. Throws InvalidArgumentException on non-number input.
Creates a Closure that divides a pre-defined dividend by whatever number it receives. Result is `dividend / value`. Use this when the numerator is the constant and you want to vary the denominator — see `divideBy()` for the reverse.
/**
* @param int|float $dividend Defaults to 1. The fixed numerator.
* @return Closure(int|float):float
* @throws InvalidArgumentException If $dividend is not int or float.
*/
Numbers\divideInto($dividend = 1): ClosureWhen Numbers\divideInto() is called, it returns the following Closure which can be used like a regular function.
/**
* @param int|float $value
* @return float Result of ($dividend / $value).
*/
$function (int|float $value): floatThis can be used to create a simple closure which can be used as a regular function.
// Create a function that divides 12 by whatever it receives.
$twelveOver = Numbers\divideInto(12);
// Called as a function.
echo $twelveOver(4); // 3.0
echo $twelveOver(2); // 6.0
// Used in a higher order function.
$array = array_map($twelveOver, [1, 2, 3, 4]);
print_r($array); // [12.0, 6.0, 4.0, 3.0]This can be called inline using currying.
echo Numbers\divideInto(100)(4); // 25.0If 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\divideInto(60), [1, 2, 3, 4, 5, 6]);
print_r($array); // [60.0, 30.0, 20.0, 15.0, 12.0, 10.0]