| @@ 17-43 (lines=27) @@ | ||
| 14 | * |
|
| 15 | * @package Zicht\Itertools\lib |
|
| 16 | */ |
|
| 17 | class FilterIterator extends \FilterIterator implements FiniteIterableInterface |
|
| 18 | { |
|
| 19 | use FiniteIterableTrait; |
|
| 20 | ||
| 21 | /** @var \Closure */ |
|
| 22 | private $func; |
|
| 23 | ||
| 24 | /** |
|
| 25 | * FilterIterator constructor. |
|
| 26 | * |
|
| 27 | * @param \Closure $func |
|
| 28 | * @param \Iterator $iterable |
|
| 29 | */ |
|
| 30 | public function __construct(\Closure $func, \Iterator $iterable) |
|
| 31 | { |
|
| 32 | $this->func = $func; |
|
| 33 | parent::__construct($iterable); |
|
| 34 | } |
|
| 35 | ||
| 36 | /** |
|
| 37 | * @{inheritDoc} |
|
| 38 | */ |
|
| 39 | public function accept() |
|
| 40 | { |
|
| 41 | return call_user_func_array($this->func, [$this->current(), $this->key()]); |
|
| 42 | } |
|
| 43 | } |
|
| 44 | ||
| @@ 17-45 (lines=29) @@ | ||
| 14 | * |
|
| 15 | * @package Zicht\Itertools\lib |
|
| 16 | */ |
|
| 17 | class MapByIterator extends \IteratorIterator implements FiniteIterableInterface |
|
| 18 | { |
|
| 19 | use FiniteIterableTrait; |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @var callable |
|
| 23 | */ |
|
| 24 | private $func; |
|
| 25 | ||
| 26 | /** |
|
| 27 | * MapByIterator constructor. |
|
| 28 | * |
|
| 29 | * @param \Closure $func |
|
| 30 | * @param \Iterator $iterable |
|
| 31 | */ |
|
| 32 | public function __construct(\Closure $func, \Iterator $iterable) |
|
| 33 | { |
|
| 34 | parent::__construct($iterable); |
|
| 35 | $this->func = $func; |
|
| 36 | } |
|
| 37 | ||
| 38 | /** |
|
| 39 | * @{inheritDoc} |
|
| 40 | */ |
|
| 41 | public function key() |
|
| 42 | { |
|
| 43 | return call_user_func($this->func, $this->current(), parent::key()); |
|
| 44 | } |
|
| 45 | } |
|
| 46 | ||