1 | <?php |
||
2 | |||
3 | /** |
||
4 | * For the full copyright and license information, please view |
||
5 | * the LICENSE file that was distributed with this source code. |
||
6 | */ |
||
7 | |||
8 | declare(strict_types=1); |
||
9 | |||
10 | namespace loophp\iterators; |
||
11 | |||
12 | use Generator; |
||
13 | use IteratorAggregate; |
||
14 | use MultipleIterator; |
||
15 | |||
16 | /** |
||
17 | * @template TKey |
||
18 | * @template T |
||
19 | * |
||
20 | * @implements IteratorAggregate<array<int, TKey|null>, array<int, T|null>> |
||
21 | */ |
||
22 | final class MultipleIterableAggregate implements IteratorAggregate |
||
23 | { |
||
24 | /** |
||
25 | * @param iterable<array-key, iterable<TKey, T>> $iterables |
||
26 | * @param (0|1|2|3) $flags |
||
0 ignored issues
–
show
Documentation
Bug
introduced
by
![]() |
|||
27 | */ |
||
28 | 3 | public function __construct(private iterable $iterables, private int $flags = MultipleIterator::MIT_NEED_ALL | MultipleIterator::MIT_KEYS_NUMERIC) |
|
29 | { |
||
30 | 3 | } |
|
31 | |||
32 | /** |
||
33 | * @return Generator<array<int, TKey|null>, array<int, T|null>> |
||
34 | */ |
||
35 | 3 | public function getIterator(): Generator |
|
36 | { |
||
37 | 3 | $mit = new MultipleIterator($this->flags); |
|
38 | |||
39 | 3 | foreach ($this->iterables as $key => $iterable) { |
|
40 | 3 | $mit->attachIterator( |
|
41 | 3 | (new IterableIteratorAggregate($iterable))->getIterator(), |
|
42 | 3 | $key |
|
43 | 3 | ); |
|
44 | } |
||
45 | |||
46 | 3 | yield from $mit; |
|
47 | } |
||
48 | } |
||
49 |