move applyWithArity to internal namespace

This commit is contained in:
Kacper Donat 2026-10-27 23:00:38 +01:00
parent a09e6840d4
commit eac27c9e63
5 changed files with 43 additions and 37 deletions

View File

@ -23,6 +23,7 @@
}, },
"files": [ "files": [
"./src/functions.php", "./src/functions.php",
"./src/Internal/functions.php",
"./src/Predicates/index.php", "./src/Predicates/index.php",
"./src/Collections/Internal/functions.php", "./src/Collections/Internal/functions.php",
"./src/Collections/Internal/containers.php", "./src/Collections/Internal/containers.php",

View File

@ -498,18 +498,6 @@ parameters:
count: 1 count: 1
path: src/Utils/index.php path: src/Utils/index.php
-
message: '#^Function Kadet\\Functional\\applyWithArity\(\) has no return type specified\.$#'
identifier: missingType.return
count: 1
path: src/Utils/index.php
-
message: '#^Function Kadet\\Functional\\applyWithArity\(\) has parameter \$args with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: src/Utils/index.php
- -
message: '#^Function Kadet\\Functional\\curry\(\) has parameter \$args with no type specified\.$#' message: '#^Function Kadet\\Functional\\curry\(\) has parameter \$args with no type specified\.$#'
identifier: missingType.parameter identifier: missingType.parameter

View File

@ -0,0 +1,39 @@
<?php
/**
* Copyright 2026 Kacper Donat
*
* @author Kacper "Kadet" Donat <kacper@kadet.net>
*
* Full license available in separate LICENSE file
*/
namespace Kadet\Functional\Internal;
use function Kadet\Functional\apply;
use function Kadet\Functional\partial;
/**
* The argument dispatch of apply(), with the arity of $callable already known: it calls $call when there are enough
* arguments and partially applies $callable otherwise.
*
* @internal
*
* @param array<mixed> $args
*/
function applyWithArity(callable $callable, callable $call, bool $variadic, int $required, int $all, array $args): mixed
{
switch (true) {
case $variadic:
return partial($callable, ...$args);
case count($args) >= $all:
$applied = $call(...array_slice($args, 0, $all));
return is_callable($applied) ? apply($applied, ...array_slice($args, $all)) : $applied;
case count($args) >= $required:
return $call(...$args);
default:
return partial($callable, ...$args);
}
}

View File

@ -11,7 +11,7 @@ namespace Kadet\Functional\Utils;
use function Kadet\Functional\apply; use function Kadet\Functional\apply;
use function Kadet\Functional\applyWithArity; use function Kadet\Functional\Internal\applyWithArity;
use Kadet\Functional\Compilable; use Kadet\Functional\Compilable;
use function Kadet\Functional\compile; use function Kadet\Functional\compile;
use Kadet\Functional\Decorator; use Kadet\Functional\Decorator;

View File

@ -15,6 +15,8 @@ use Kadet\Functional\Utils\FunctionPipeline;
use Kadet\Functional\Utils\MemoizedFunction; use Kadet\Functional\Utils\MemoizedFunction;
use Kadet\Functional\Utils\PartiallyAppliedFunction; use Kadet\Functional\Utils\PartiallyAppliedFunction;
use function Kadet\Functional\Internal\applyWithArity;
function partial(callable $callable, ...$args): PartiallyAppliedFunction function partial(callable $callable, ...$args): PartiallyAppliedFunction
{ {
return new PartiallyAppliedFunction($callable, ...$args); return new PartiallyAppliedFunction($callable, ...$args);
@ -39,30 +41,6 @@ function apply(callable $callable, ...$args)
} }
} }
/**
* The argument dispatch of apply(), with the arity of $callable already known: it calls $call when there are enough
* arguments and partially applies $callable otherwise.
*
* @internal
*/
function applyWithArity(callable $callable, callable $call, bool $variadic, int $required, int $all, array $args)
{
switch (true) {
case $variadic:
return partial($callable, ...$args);
case count($args) >= $all:
$applied = $call(...array_slice($args, 0, $all));
return is_callable($applied) ? apply($applied, ...array_slice($args, $all)) : $applied;
case count($args) >= $required:
return $call(...$args);
default:
return partial($callable, ...$args);
}
}
function curry(callable $callable, ?int $threshold = null, ...$args): CurriedFunction function curry(callable $callable, ?int $threshold = null, ...$args): CurriedFunction
{ {
return new CurriedFunction($callable, $threshold, ...$args); return new CurriedFunction($callable, $threshold, ...$args);