InvalidArgumentException on non-number input.
Creates a Closure that returns the remainder when a pre-defined dividend is divided by the passed value. Result is `dividend % value`. See `remainderBy()` for the reverse direction.
/**
* @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\remainderInto($dividend = 1): ClosureWhen Numbers\remainderInto() 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 returns the remainder of 10 divided by whatever it receives.
$modOfTen = Numbers\remainderInto(10);
// Called as a function.
echo $modOfTen(3); // 1
echo $modOfTen(4); // 2
echo $modOfTen(5); // 0
// Used in a higher order function.
$array = array_map($modOfTen, [3, 4, 5, 6]);
print_r($array); // [1, 2, 0, 4]This can be called inline using currying.
echo Numbers\remainderInto(100)(7); // 2If 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\remainderInto(10), [1, 2, 3, 4]);
print_r($array); // [0, 0, 1, 2]