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