| Total Complexity | 12 |
| Total Lines | 60 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php declare(strict_types=1); |
||
| 8 | final class LazyCollection implements Collection |
||
| 9 | { |
||
| 10 | private $elements; |
||
| 11 | |||
| 12 | 10 | public function __construct(Traversable $elements) |
|
| 15 | } |
||
| 16 | |||
| 17 | 9 | public function getIterator(): Traversable |
|
| 18 | { |
||
| 19 | 9 | yield from $this->elements; |
|
| 20 | } |
||
| 21 | |||
| 22 | 2 | public function merge(Collection $other): Collection |
|
| 23 | { |
||
| 24 | return self::createFromClosure(function () use ($other) { |
||
| 25 | 2 | foreach ($this as $e) { |
|
| 26 | 2 | yield $e; |
|
| 27 | } |
||
| 28 | 2 | foreach ($other as $e) { |
|
| 29 | 2 | yield $e; |
|
| 30 | } |
||
| 31 | 2 | }); |
|
| 32 | } |
||
| 33 | |||
| 34 | 2 | public function filter(callable $f): Collection |
|
| 40 | } |
||
| 41 | } |
||
| 42 | 2 | }); |
|
| 43 | } |
||
| 44 | |||
| 45 | 2 | public function map(callable $f): Collection |
|
| 46 | { |
||
| 47 | return self::createFromClosure(function () use ($f) { |
||
| 48 | 2 | foreach ($this as $e) { |
|
| 49 | 2 | yield $f($e); |
|
| 50 | } |
||
| 51 | 2 | }); |
|
| 52 | } |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @param mixed $initial |
||
| 56 | * @param callable $f |
||
| 57 | * |
||
| 58 | * @return mixed |
||
| 59 | */ |
||
| 60 | 1 | public function reduce($initial, callable $f) |
|
| 63 | } |
||
| 64 | |||
| 65 | 6 | private static function createFromClosure(Closure $f): Collection |
|
| 68 | } |
||
| 69 | } |
||
| 70 |