1: <?php
2:
3: /**
4: * This file is part of the Nette Framework (https://nette.org)
5: * Copyright (c) 2004 David Grudl (https://davidgrudl.com)
6: */
7:
8: namespace Nette\Iterators;
9:
10: use Nette;
11:
12:
13: /**
14: * Applies the callback to the elements of the inner iterator.
15: */
16: class Mapper extends \IteratorIterator
17: {
18: /** @var callable */
19: private $callback;
20:
21:
22: public function __construct(\Traversable $iterator, $callback)
23: {
24: parent::__construct($iterator);
25: $this->callback = Nette\Utils\Callback::check($callback);
26: }
27:
28:
29: public function current()
30: {
31: return call_user_func($this->callback, parent::current(), parent::key());
32: }
33:
34: }
35: