| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace Improved; |
||
| 6 | |||
| 7 | /** |
||
| 8 | * Applies the callback to the elements of the iterator, replacing the value. |
||
| 9 | * |
||
| 10 | * @param iterable $iterable |
||
| 11 | * @param callable $callback |
||
| 12 | * @return \Generator |
||
| 13 | */ |
||
| 14 | 11 | function iterable_map(iterable $iterable, callable $callback): \Generator |
|
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 15 | { |
||
| 16 | 10 | foreach ($iterable as $key => $value) { |
|
| 17 | 9 | yield $key => call_user_func($callback, $value, $key); |
|
| 18 | } |
||
| 19 | } |
||
| 20 |