1
|
|
|
<?php |
2
|
|
|
declare(strict_types = 1); |
3
|
|
|
|
4
|
|
|
namespace Innmind\Immutable\Set; |
5
|
|
|
|
6
|
|
|
use Innmind\Immutable\{ |
7
|
|
|
Map, |
8
|
|
|
Sequence, |
9
|
|
|
Set, |
10
|
|
|
Str, |
11
|
|
|
Maybe, |
12
|
|
|
SideEffect, |
13
|
|
|
}; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @template T |
17
|
|
|
* @psalm-immutable |
18
|
|
|
*/ |
19
|
|
|
final class Defer implements Implementation |
20
|
|
|
{ |
21
|
|
|
/** @var Sequence\Implementation<T> */ |
22
|
|
|
private Sequence\Implementation $values; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @param Sequence\Implementation<T> $values |
26
|
|
|
*/ |
27
|
|
|
public function __construct(Sequence\Implementation $values) |
28
|
26 |
|
{ |
29
|
|
|
$this->values = $values->distinct(); |
30
|
26 |
|
} |
31
|
26 |
|
|
32
|
26 |
|
/** |
33
|
26 |
|
* @param T $element |
|
|
|
|
34
|
|
|
* |
35
|
1 |
|
* @return self<T> |
36
|
|
|
*/ |
37
|
1 |
|
public function __invoke($element): self |
38
|
|
|
{ |
39
|
|
|
return new self(($this->values)($element)); |
40
|
3 |
|
} |
41
|
|
|
|
42
|
3 |
|
/** |
43
|
|
|
* @template A |
44
|
|
|
* @psalm-pure |
45
|
|
|
* |
46
|
|
|
* @param \Generator<A> $generator |
47
|
|
|
* |
48
|
1 |
|
* @return self<A> |
49
|
|
|
*/ |
50
|
1 |
|
public static function of(\Generator $generator): self |
51
|
|
|
{ |
52
|
|
|
return new self(new Sequence\Defer($generator)); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function size(): int |
56
|
14 |
|
{ |
57
|
|
|
return $this->values->size(); |
58
|
14 |
|
} |
59
|
|
|
|
60
|
|
|
public function count(): int |
61
|
|
|
{ |
62
|
|
|
return $this->values->size(); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
2 |
|
* @return \Iterator<int, T> |
67
|
|
|
*/ |
68
|
2 |
|
public function iterator(): \Iterator |
69
|
|
|
{ |
70
|
|
|
return $this->values->iterator(); |
71
|
1 |
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
2 |
|
* @param Implementation<T> $set |
75
|
2 |
|
* |
76
|
2 |
|
* @return self<T> |
77
|
2 |
|
*/ |
78
|
|
|
public function intersect(Implementation $set): self |
79
|
|
|
{ |
80
|
2 |
|
if ($this === $set) { |
|
|
|
|
81
|
2 |
|
// this is necessary as the manipulation of the same iterator below |
82
|
|
|
// leads to unexpected behaviour |
83
|
2 |
|
return $this; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
return new self($this->values->intersect($set->sequence())); |
87
|
2 |
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @param T $element |
91
|
|
|
*/ |
92
|
|
|
public function contains($element): bool |
93
|
|
|
{ |
94
|
|
|
return $this->values->contains($element); |
95
|
1 |
|
} |
96
|
|
|
|
97
|
1 |
|
/** |
98
|
1 |
|
* @param T $element |
99
|
|
|
* |
100
|
1 |
|
* @return self<T> |
101
|
|
|
*/ |
102
|
|
|
public function remove($element): self |
103
|
|
|
{ |
104
|
|
|
if (!$this->contains($element)) { |
105
|
|
|
return $this; |
106
|
2 |
|
} |
107
|
|
|
|
108
|
2 |
|
return new self($this->values->filter( |
109
|
|
|
static fn($value) => $value !== $element, |
110
|
|
|
)); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @param Implementation<T> $set |
115
|
|
|
* |
116
|
1 |
|
* @return self<T> |
117
|
|
|
*/ |
118
|
1 |
|
public function diff(Implementation $set): self |
119
|
1 |
|
{ |
120
|
|
|
return new self($this->values->diff($set->sequence())); |
121
|
|
|
} |
122
|
1 |
|
|
123
|
1 |
|
/** |
124
|
1 |
|
* @param Implementation<T> $set |
125
|
1 |
|
*/ |
126
|
1 |
|
public function equals(Implementation $set): bool |
127
|
1 |
|
{ |
128
|
|
|
if ($this->size() !== $set->size()) { |
129
|
1 |
|
return false; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
return $this->intersect($set)->size() === $this->size(); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @param callable(T): bool $predicate |
137
|
1 |
|
* |
138
|
|
|
* @return self<T> |
139
|
1 |
|
*/ |
140
|
1 |
|
public function filter(callable $predicate): self |
141
|
1 |
|
{ |
142
|
1 |
|
return new self($this->values->filter($predicate)); |
143
|
|
|
} |
144
|
|
|
|
145
|
1 |
|
/** |
146
|
1 |
|
* @param callable(T): void $function |
147
|
|
|
*/ |
148
|
1 |
|
public function foreach(callable $function): SideEffect |
149
|
|
|
{ |
150
|
|
|
return $this->values->foreach($function); |
151
|
|
|
} |
152
|
1 |
|
|
153
|
|
|
/** |
154
|
|
|
* @template D |
155
|
|
|
* |
156
|
|
|
* @param callable(T): D $discriminator |
157
|
|
|
* |
158
|
1 |
|
* @return Map<D, Set<T>> |
159
|
|
|
*/ |
160
|
1 |
|
public function groupBy(callable $discriminator): Map |
161
|
1 |
|
{ |
162
|
|
|
return $this |
163
|
|
|
->values |
164
|
1 |
|
->groupBy($discriminator) |
165
|
|
|
->map(static fn(mixed $_, $sequence) => Set::of(...$sequence->toList())); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* @template S |
170
|
|
|
* |
171
|
|
|
* @param callable(T): S $function |
172
|
1 |
|
* |
173
|
|
|
* @return self<S> |
174
|
1 |
|
*/ |
175
|
1 |
|
public function map(callable $function): self |
176
|
|
|
{ |
177
|
1 |
|
return new self($this->values->map($function)); |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* @param callable(T): bool $predicate |
182
|
|
|
* |
183
|
1 |
|
* @return Map<bool, Set<T>> |
184
|
|
|
*/ |
185
|
1 |
|
public function partition(callable $predicate): Map |
186
|
1 |
|
{ |
187
|
|
|
return $this |
188
|
|
|
->values |
189
|
|
|
->partition($predicate) |
190
|
|
|
->map(static fn($_, $sequence) => Set::of(...$sequence->toList())); |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* @param callable(T, T): int $function |
195
|
|
|
* |
196
|
1 |
|
* @return Sequence<T> |
197
|
|
|
*/ |
198
|
|
|
public function sort(callable $function): Sequence |
199
|
1 |
|
{ |
200
|
|
|
return $this |
201
|
|
|
->values |
202
|
|
|
->sort($function) |
203
|
|
|
->toSequence(); |
204
|
|
|
} |
205
|
1 |
|
|
206
|
1 |
|
/** |
207
|
|
|
* @param Implementation<T> $set |
208
|
1 |
|
* |
209
|
1 |
|
* @return self<T> |
210
|
1 |
|
*/ |
211
|
|
|
public function merge(Implementation $set): self |
212
|
1 |
|
{ |
213
|
|
|
return new self($this->values->append($set->sequence())); |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* @template R |
218
|
|
|
* @param R $carry |
|
|
|
|
219
|
|
|
* @param callable(R, T): R $reducer |
220
|
|
|
* |
221
|
2 |
|
* @return R |
222
|
|
|
*/ |
223
|
|
|
public function reduce($carry, callable $reducer) |
224
|
|
|
{ |
225
|
|
|
return $this->values->reduce($carry, $reducer); |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
/** |
229
|
2 |
|
* @return Implementation<T> |
230
|
2 |
|
*/ |
231
|
|
|
public function clear(): Implementation |
232
|
1 |
|
{ |
233
|
2 |
|
return Primitive::of(); |
234
|
|
|
} |
235
|
2 |
|
|
236
|
2 |
|
public function empty(): bool |
237
|
2 |
|
{ |
238
|
2 |
|
return $this->values->empty(); |
239
|
2 |
|
} |
240
|
|
|
|
241
|
2 |
|
public function find(callable $predicate): Maybe |
242
|
|
|
{ |
243
|
|
|
return $this->values->find($predicate); |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
/** |
247
|
|
|
* @return Sequence\Implementation<T> |
248
|
|
|
*/ |
249
|
1 |
|
public function sequence(): Sequence\Implementation |
250
|
|
|
{ |
251
|
1 |
|
return $this->values; |
252
|
|
|
} |
253
|
|
|
} |
254
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths