Passed
Push — master ( 2236ae...d0b86a )
by Pol
11:24
created

Map::of()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 5
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace loophp\fpt;
6
7
use Closure;
8
use Generator;
9
10
use function call_user_func;
11
12
// phpcs:disable Generic.Files.LineLength.TooLong
13
14
/**
15
 * @psalm-immutable
16
 */
17
final class Map
18
{
19
    /**
20
     * @psalm-pure
21
     */
22
    public static function of(): Closure
23
    {
24
        return static fn (callable $callable): Closure => static function (iterable $iterable) use ($callable): Generator {
25
            foreach ($iterable as $key => $item) {
26
                yield $key => call_user_func($callable, $item);
27
            }
28
        };
29
    }
30
}
31