You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 8ff4eed
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: docs/collection/api/collection.md
+17-17Lines changed: 17 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -101,7 +101,7 @@ count(): int
101
101
Returns the number of elements in the collection.
102
102
103
103
```php
104
-
countWhere(Closure $predicate): int
104
+
countWhere(Closure $predicate): int<0,max>
105
105
```
106
106
Returns the number of elements matching the predicate `(E, int): bool`.
107
107
@@ -135,7 +135,7 @@ Reduce, or `null` if empty.
135
135
```php
136
136
sum(?Closure $selector = null): int|float
137
137
```
138
-
Sum of all elements, or values returned by the selector `(E, int): int|float`.
138
+
Sum of all elements, or values returned by the selector `(E, int): int|float`. The return type narrows to `int` when every summed value is an `int` — a `Collection<int>`, or a selector declared to return `int` — and stays `int|float` otherwise.
Maximum element, or `null` if empty. Optional selector `(E, int): mixed`.
169
169
170
170
```php
171
-
minOf(Closure $selector): mixed
171
+
minOf(Closure $selector): R
172
172
```
173
-
Returns the minimum value produced by the selector `(E, int): mixed`. Unlike `min()`, returns the **selector value** itself, not the element. Throws `NoSuchElementException` if empty.
173
+
Returns the minimum value produced by the selector `(E, int): R`. Unlike `min()`, returns the **selector value** itself, not the element. The return type follows the selector — one declared `: int` yields `int`. Throws `NoSuchElementException` if empty.
174
174
175
175
```php
176
-
minOfOrNull(Closure $selector): mixed
176
+
minOfOrNull(Closure $selector): R|null
177
177
```
178
178
Returns the minimum selector value, or `null` if empty.
179
179
180
180
```php
181
-
maxOf(Closure $selector): mixed
181
+
maxOf(Closure $selector): R
182
182
```
183
-
Returns the maximum value produced by the selector `(E, int): mixed`. Unlike `max()`, returns the **selector value** itself, not the element. Throws `NoSuchElementException` if empty.
183
+
Returns the maximum value produced by the selector `(E, int): R`. Unlike `max()`, returns the **selector value** itself, not the element. The return type follows the selector — one declared `: int` yields `int`. Throws `NoSuchElementException` if empty.
184
184
185
185
```php
186
-
maxOfOrNull(Closure $selector): mixed
186
+
maxOfOrNull(Closure $selector): R|null
187
187
```
188
188
Returns the maximum selector value, or `null` if empty.
189
189
@@ -216,7 +216,7 @@ Filter by predicate `(E, int): bool`. Returns `ImmutableList` for lists, `Immuta
216
216
```php
217
217
filterNotNull(): Collection<E>
218
218
```
219
-
Filter out `null` elements.
219
+
Filter out `null` elements. The element type narrows to exclude `null` — `Collection<string|null>` becomes `Collection<string>`.
Transform and flatten. Closure: `(E, int): iterable<R>`.
240
240
241
241
```php
242
-
flatten(): Collection<mixed>
242
+
flatten(): Collection<V>
243
243
```
244
-
Flatten a collection of iterables.
244
+
Flatten a collection of iterables, one level deep. Iterable elements contribute their own values (`V` is the element type of `E`); non-iterable elements are kept as-is. So `Collection<ImmutableList<int>>` becomes `Collection<int>`, `Collection<array<int>|string>` becomes `Collection<int|string>`, and `Collection<string>` stays `Collection<string>`. Only one level is removed — flattening `Collection<ImmutableList<ImmutableList<int>>>` yields `Collection<ImmutableList<int>>`.
Group elements by key selector `(E, int): K`. When a `$valueTransform``(E, int): V` is provided, each element is transformed before being added to its group — the result is `Map<K, ImmutableList<V>>`.
334
334
335
335
```php
336
-
intersect(iterable $other): ImmutableSet<E>
336
+
intersect(iterable<V> $other): ImmutableSet<E&V>
337
337
```
338
-
Elements present in both this collection and the iterable. Returns a set (duplicates removed).
338
+
Elements present in both this collection and the iterable. Returns a set (duplicates removed). The element type narrows to `E&V` — only values that can belong to both sides.
339
339
340
340
```php
341
-
union(iterable $other): ImmutableSet<E>
341
+
union(iterable<NE> $other): ImmutableSet<E|NE>
342
342
```
343
-
All elements from both this collection and the iterable. Returns a set (duplicates removed).
343
+
All elements from both this collection and the iterable. Returns a set (duplicates removed). The element type widens to `E|NE`, like `add()`.
344
344
345
345
```php
346
-
subtract(iterable $other): ImmutableSet<E>
346
+
subtract(iterable<mixed> $other): ImmutableSet<E>
347
347
```
348
-
Elements present in this collection but not in the iterable. Returns a set (duplicates removed).
348
+
Elements present in this collection but not in the iterable. Returns a set (duplicates removed). The element type is always `E` — any iterable may be subtracted.
Convert to PHP array. Only works with scalar keys. Throws `ConversionException` for object keys or key collisions.
240
+
Convert to PHP array. Only works with scalar keys. Throws `ConversionException` for object keys or key collisions. The key type is preserved when `K` is a valid array key — a `Map<string, int>` yields `array<string, int>`; a map with keys PHP cannot use natively falls back to `array<array-key, V>`.
Copy file name to clipboardExpand all lines: src/List/ListLogic.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -239,9 +239,9 @@ public function flatMap(Closure $transform): ImmutableList
239
239
/**
240
240
* {@inheritDoc}
241
241
*
242
-
* @return ImmutableList<mixed>
242
+
* @return ImmutableList<(E is iterable<mixed> ? value-of<E|array{}> : E)>
243
243
*/
244
-
#[NoDiscard]
244
+
#[NoDiscard]// @phpstan-ignore conditionalType.subjectNotFound, return.unresolvableType (in classes with a concrete E the conditional subject is already substituted and stays unevaluated)
0 commit comments