Completed
Push — master ( cd157d...8cb219 )
by Arnold
06:18
created

iterable_after()   A

Complexity

Conditions 6
Paths 5

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 6
nc 5
nop 3
dl 0
loc 12
rs 9.2222
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace Improved;
4
5
/**
6
 * Get elements after a match is found.
7
 *
8
 * @param iterable $iterable
9
 * @param callable $matcher
10
 * @param bool     $including
11
 * @return \Generator
12
 */
13
function iterable_after(iterable $iterable, callable $matcher, bool $including = false): \Generator
14
{
15
    $found = false;
16
17
    foreach ($iterable as $key => $value) {
18
        $matched = $found || (bool)call_user_func($matcher, $value, $key);
19
20
        if ($found || ($matched && $including)) {
21
            yield $key => $value;
22
        }
23
24
        $found = $matched;
25
    }
26
}
27