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 Closure; |
||
13 | use Generator; |
||
14 | use IteratorAggregate; |
||
15 | |||
16 | /** |
||
17 | * @template TKey |
||
18 | * @template T |
||
19 | * @template W |
||
20 | * |
||
21 | * @implements IteratorAggregate<TKey, W> |
||
22 | */ |
||
23 | final class MapIterableAggregate implements IteratorAggregate |
||
24 | { |
||
25 | /** |
||
26 | * @param iterable<TKey, T> $iterable |
||
27 | * @param (Closure(T, TKey, iterable<TKey, T>): W) $closure |
||
0 ignored issues
–
show
Documentation
Bug
introduced
by
![]() |
|||
28 | */ |
||
29 | 1 | public function __construct(private iterable $iterable, private Closure $closure) |
|
30 | { |
||
31 | 1 | } |
|
32 | |||
33 | /** |
||
34 | * @return Generator<TKey, W> |
||
35 | */ |
||
36 | 1 | public function getIterator(): Generator |
|
37 | { |
||
38 | 1 | foreach ($this->iterable as $key => $value) { |
|
39 | 1 | yield $key => ($this->closure)($value, $key, $this->iterable); |
|
40 | } |
||
41 | } |
||
42 | } |
||
43 |