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:
11:
12: /**
13: * Applies the callback to the elements of the inner iterator.
14: */
15: class Mapper extends \IteratorIterator
16: {
17: /** @var callable */
18: private $callback;
19:
20:
21: public function __construct(\Traversable $iterator, callable $callback)
22: {
23: parent::__construct($iterator);
24: $this->callback = $callback;
25: }
26:
27:
28: public function current()
29: {
30: return call_user_func($this->callback, parent::current(), parent::key());
31: }
32: }
33: