fix partial application of function with applied placeholders

This commit is contained in:
Kacper Donat 2018-09-02 20:26:49 +02:00
parent 024d97d46c
commit f8ea3de9f7
2 changed files with 10 additions and 1 deletions

View File

@ -48,7 +48,7 @@ class PartiallyAppliedFunction implements Decorator
{
$result = [];
foreach ($this->arguments as $argument) {
$result[] = $argument === PLACEHOLDER
$result[] = $argument === PLACEHOLDER && !empty($args)
? array_shift($args)
: $argument;
}

View File

@ -102,4 +102,13 @@ class PartialApplicationTest extends \PHPUnit\Framework\TestCase
$this->assertEquals(6, $applied(3));
$this->assertEquals(24, $applied(4));
}
public function testPartialApplicationOfAppliedFunctionWithPlaceholders()
{
$applied = f\partial('array_merge', _, _, ['c']);
$double = f\partial($applied, ['a']);
$this->assertEquals(['a', 'b', 'c', 'd'], $double(['b'], ['d']));
}
}