Numbers\remainderInto()

transformer returns Closure pure throws
number → (number → float)
At a glance — Bind a dividend; the returned Closure yields the modulus of the bound number divided by whatever you pass in. Throws 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): Closure

Returned Closure

When 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): 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 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]

Curried

This can be called inline using currying.

echo Numbers\remainderInto(100)(7); // 2

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\remainderInto(10), [1, 2, 3, 4]);
print_r($array); // [0, 0, 1, 2]

Details

Numbers Functions

Releated Number arithmetic Functions