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: * @package Nette\Iterators
11: */
12:
13:
14:
15: /**
16: * Applies the callback to the elements of the inner iterator.
17: *
18: * @author David Grudl
19: * @package Nette\Iterators
20: */
21: class NMapIterator extends IteratorIterator
22: {
23: /** @var callback */
24: private $callback;
25:
26:
27: /**
28: * Constructs a filter around another iterator.
29: * @param
30: * @param callback
31: */
32: public function __construct(Traversable $iterator, $callback)
33: {
34: parent::__construct($iterator);
35: $this->callback = $callback;
36: }
37:
38:
39:
40: public function current()
41: {
42: return call_user_func($this->callback, parent::current(), parent::key());
43: }
44:
45: }
46: