move applyWithArity to internal namespace
This commit is contained in:
parent
a09e6840d4
commit
eac27c9e63
@ -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",
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
39
src/Internal/functions.php
Normal file
39
src/Internal/functions.php
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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;
|
||||||
|
|||||||
@ -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);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user