Mapper.php 620 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. /**
  3. * This file is part of the Nette Framework (https://nette.org)
  4. * Copyright (c) 2004 David Grudl (https://davidgrudl.com)
  5. */
  6. declare(strict_types=1);
  7. namespace Nette\Iterators;
  8. /**
  9. * Applies the callback to the elements of the inner iterator.
  10. */
  11. class Mapper extends \IteratorIterator
  12. {
  13. /** @var callable */
  14. private $callback;
  15. public function __construct(\Traversable $iterator, callable $callback)
  16. {
  17. parent::__construct($iterator);
  18. $this->callback = $callback;
  19. }
  20. #[\ReturnTypeWillChange]
  21. public function current()
  22. {
  23. return ($this->callback)(parent::current(), parent::key());
  24. }
  25. }