Composable numeric operations. Each constructor binds a fixed operand up front and returns a reusable Closure that accepts the other operand later. All functions accept
intorfloatonly — passing anything else throwsInvalidArgumentException.
$addTo5 = Num\sum(5);
$addTo5(15.5); // 20.5
$addTo5(-2); // 3
$divideBy3 = Num\divideBy(3);
$divideBy3(12); // 4.0
$divideBy3(10); // 3.3333333333333
// Note the argument order: subtract(X)(Y) computes Y − X
$minusTen = Num\subtract(10);
$minusTen(25); // 15Also: multiply, divideInto, remainderBy, remainderInto, power, root, round.
$isEven = Num\isMultipleOf(2);
$isEven(12); // true
$isEven(13); // false
$isEven(0); // false — zero is never a multiple here
$factorOf12 = Num\isFactorOf(12);
$factorOf12(3); // true — 12 / 3 has no remainder
$factorOf12(5); // false// Each call returns a fresh accumulator; call with null (or no arg) to finalise.
$total = Num\accumulatorInt(0);
$total = $total(5);
$total = $total(10);
$total = $total(-3);
echo $total(); // 12accumulatorFloat follows the same pattern for floats.
Arr\filter and Arr\sumWhere.