/** * * @param \Traversable $iterator * @param Callable $callback */ public function __construct(\Traversable $iterator, $callback) { $this->_iterator = $iterator; while ($this->_iterator instanceof \IteratorAggregate) { $this->_iterator = $this->_iterator->getIterator(); } $this->_callback = $callback; }
private function project() { $projection = $this->projection; $this->currentIterator = $projection($this->innerIterator->current(), $this->innerIterator->key(), $this->innerIterator); if ($this->currentIterator instanceof \IteratorAggregate) { $this->currentIterator = $this->currentIterator->getIterator(); } elseif ($this->currentIterator instanceof \Iterator !== true) { throw new \BadMethodCallException('Projection did not return an iterator'); } $this->projectionNeeded = false; }