fix partial application of function with applied placeholders
This commit is contained in:
		
							parent
							
								
									024d97d46c
								
							
						
					
					
						commit
						f8ea3de9f7
					
				| @ -48,7 +48,7 @@ class PartiallyAppliedFunction implements Decorator | |||||||
|     { |     { | ||||||
|         $result = []; |         $result = []; | ||||||
|         foreach ($this->arguments as $argument) { |         foreach ($this->arguments as $argument) { | ||||||
|             $result[] = $argument === PLACEHOLDER |             $result[] = $argument === PLACEHOLDER && !empty($args) | ||||||
|                 ? array_shift($args) |                 ? array_shift($args) | ||||||
|                 : $argument; |                 : $argument; | ||||||
|         } |         } | ||||||
|  | |||||||
| @ -102,4 +102,13 @@ class PartialApplicationTest extends \PHPUnit\Framework\TestCase | |||||||
|         $this->assertEquals(6,  $applied(3)); |         $this->assertEquals(6,  $applied(3)); | ||||||
|         $this->assertEquals(24, $applied(4)); |         $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'])); | ||||||
|  |     } | ||||||
| } | } | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user