1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace Improved; |
||
6 | |||
7 | /** |
||
8 | * Apply a callback to each element. |
||
9 | * |
||
10 | * @param iterable $iterable |
||
11 | * @param callable $callback |
||
12 | * @return \Generator |
||
13 | */ |
||
14 | 6 | function iterable_apply(iterable $iterable, callable $callback): \Generator |
|
0 ignored issues
–
show
introduced
by
![]() |
|||
15 | { |
||
16 | 5 | foreach ($iterable as $key => $value) { |
|
17 | 4 | call_user_func($callback, $value, $key); |
|
18 | |||
19 | 4 | yield $key => $value; |
|
20 | } |
||
21 | } |
||
22 |