force call if no args supplied for curried function
This commit is contained in:
parent
f8eb8a0cf7
commit
17c96b2834
@ -14,6 +14,8 @@ use function Kadet\Functional\reflect;
|
||||
|
||||
class CurriedFunction extends PartiallyAppliedFunction
|
||||
{
|
||||
const INF = PHP_INT_MAX;
|
||||
|
||||
private $threshold;
|
||||
|
||||
/**
|
||||
@ -61,6 +63,10 @@ class CurriedFunction extends PartiallyAppliedFunction
|
||||
*/
|
||||
public function __invoke(...$args)
|
||||
{
|
||||
if (count($args) === 0) {
|
||||
return $this->call();
|
||||
}
|
||||
|
||||
$applied = $this->apply(...$args);
|
||||
|
||||
if (count($applied->getArguments()) >= $this->threshold) {
|
||||
|
@ -111,6 +111,13 @@ class CurriedFunctionTest extends \PHPUnit\Framework\TestCase
|
||||
$this->assertSame('abc', $g->call('c'));
|
||||
}
|
||||
|
||||
public function testForceCallIfNoArgs()
|
||||
{
|
||||
$f = f\curry($this->variadic, f\Utils\CurriedFunction::INF);
|
||||
|
||||
$this->assertSame('abcdef', $f('a', 'b', 'c')('d', 'e')('f')());
|
||||
}
|
||||
|
||||
public function testUncurry()
|
||||
{
|
||||
$f = f\curry($this->variadic, 10);
|
||||
|
Loading…
Reference in New Issue
Block a user