1: <?php
2:
3: /**
4: * This file is part of the Nette Framework (http://nette.org)
5: *
6: * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
7: *
8: * For the full copyright and license information, please view
9: * the file license.txt that was distributed with this source code.
10: */
11:
12: namespace Nette\Iterators;
13:
14: use Nette;
15:
16:
17:
18: /**
19: * Applies the callback to the elements of the inner iterator.
20: *
21: * @author David Grudl
22: */
23: class Mapper extends \IteratorIterator
24: {
25: /** @var callable */
26: private $callback;
27:
28:
29: /**
30: * Constructs a filter around another iterator.
31: * @param
32: * @param callable
33: */
34: public function __construct(\Traversable $iterator, $callback)
35: {
36: parent::__construct($iterator);
37: $this->callback = callback($callback);
38: }
39:
40:
41:
42: public function current()
43: {
44: return $this->callback->invoke(parent::current(), parent::key());
45: }
46:
47: }
48: