Partition   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 24
ccs 6
cts 6
cp 1
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 19 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace loophp\collection\Operation;
6
7
use Closure;
8
use Generator;
9
use loophp\iterators\CachingIteratorAggregate;
10
use loophp\iterators\ClosureIteratorAggregate;
11
use loophp\iterators\IterableIteratorAggregate;
12
13
/**
14
 * @immutable
15
 *
16
 * @template TKey
17
 * @template T
18
 */
19
final class Partition extends AbstractOperation
20
{
21
    /**
22
     * @return Closure(callable(T, TKey, iterable<TKey, T>): bool ...): Closure(iterable<TKey, T>): Generator<int, iterable<TKey, T>>
23
     */
24 2
    public function __invoke(): Closure
25
    {
26
        /**
27
         * @param callable(T, TKey, iterable<TKey, T>): bool ...$callbacks
28
         *
29
         * @return Closure(iterable<TKey, T>): Generator<int, iterable<TKey, T>>
30
         */
31 2
        return static fn (callable ...$callbacks): Closure =>
32
            /**
33
             * @param iterable<TKey, T> $iterable
34
             *
35
             * @return Generator<int, iterable<TKey, T>>
36
             */
37 2
            static function (iterable $iterable) use ($callbacks): Generator {
38 2
                $iteratorAggregate = (new CachingIteratorAggregate((new IterableIteratorAggregate($iterable))->getIterator()));
39
40 2
                yield new ClosureIteratorAggregate((new Filter())()(...$callbacks), [$iteratorAggregate]);
41
42 2
                yield new ClosureIteratorAggregate((new Reject())()(...$callbacks), [$iteratorAggregate]);
43 2
            };
44
    }
45
}
46