-
-
Notifications
You must be signed in to change notification settings - Fork 35
/
Run.php
47 lines (41 loc) · 1.16 KB
/
Run.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
declare(strict_types=1);
namespace loophp\collection\Transformation;
use ArrayIterator;
use Iterator;
use loophp\collection\Contract\Operation;
use loophp\collection\Contract\Transformation;
use loophp\collection\Iterator\ClosureIterator;
/**
* @psalm-template TKey
* @psalm-template TKey of array-key
* @psalm-template T
*
* @implements Transformation<TKey, T>
*/
final class Run implements Transformation
{
/**
* @var ArrayIterator<int, \loophp\collection\Contract\Operation>
*/
private $operations;
public function __construct(Operation ...$operations)
{
$this->operations = new ArrayIterator($operations);
}
public function __invoke(Iterator $collection): Iterator
{
return (
new FoldLeft(
static function (Iterator $collection, Operation $operation): ClosureIterator {
return new ClosureIterator(
$operation(),
$collection,
...array_values($operation->getArguments())
);
},
$collection
)
)($this->operations);
}
}