protected function execute(array $arguments) { if (!($function = array_shift($arguments))) { throw new InvalidArgumentException('missing function'); } elseif (!isset($arguments[0])) { throw new InvalidArgumentException('least one list is required'); } $map = array(); foreach ($arguments as &$list) { if ($list instanceof IteratorAggregate) { $list = $list->getIterator(); } elseif (is_array($list)) { $list = new ArrayIterator($list); } elseif (!$list instanceof Iterator) { throw new InvalidArgumentException('expected list'); } } $map = array(); while (true) { $values = array(); foreach ($arguments as $it) { if (!$it->valid()) { break 2; } $values[] = $it->current(); $it->next(); } $map[] = Lisphp_Runtime_Function::call($function, $values); } return new Lisphp_List($map); }
protected function execute(array $arguments) { list($predicate, $values) = $arguments; $list = array(); foreach ($values as $value) { if (Lisphp_Runtime_Function::call($predicate, array($value))) { $list[] = $value; } } return new Lisphp_List($list); }
protected function execute(array $arguments) { list($aggregate, $values) = $arguments; if ($hasResult = isset($arguments[2])) { $result = $arguments[2]; } foreach ($values as $value) { $result = $hasResult ? Lisphp_Runtime_Function::call($aggregate, array($result, $value)) : $value; $hasResult = true; } if ($hasResult) { return $result; } throw new InvalidArgumentException('the initial value or one or more elements of the list are required'); }
public function testGenericCall530() { $f = function ($a, $b) { return $a + $b; }; $val = Lisphp_Runtime_Function::call($f, array(1, 2)); $this->assertEquals(3, $val); }
function testGenericCall530() { if (version_compare(phpversion(), '5.3.0', '<')) { $this->markTestSkipped('PHP version is less than 5.3.0.'); } eval('$f = function($a, $b) { return $a + $b; };'); $val = Lisphp_Runtime_Function::call($f, array(1, 2)); $this->assertEquals(3, $val); }