1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace Improved; |
||
6 | |||
7 | /** |
||
8 | * Get elements after a match is found. |
||
9 | * |
||
10 | * @param iterable $iterable |
||
11 | * @param callable $matcher |
||
12 | * @param bool $including |
||
13 | * @return \Generator |
||
14 | */ |
||
15 | 17 | function iterable_after(iterable $iterable, callable $matcher, bool $including = false): \Generator |
|
0 ignored issues
–
show
introduced
by
![]() |
|||
16 | { |
||
17 | 16 | $found = false; |
|
18 | |||
19 | 16 | foreach ($iterable as $key => $value) { |
|
20 | 15 | $matched = $found || (bool)call_user_func($matcher, $value, $key); |
|
21 | |||
22 | 15 | if ($found || ($matched && $including)) { |
|
23 | 15 | yield $key => $value; |
|
24 | } |
||
25 | |||
26 | 15 | $found = $matched; |
|
27 | } |
||
28 | } |
||
29 |