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

Map   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 10
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 10
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A of() 0 5 2
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