Skip to content

Commit 05dd5d6

Browse files
authored
Arrays: add generic type declaration for some(), every() and map() (#298)
1 parent c7ec447 commit 05dd5d6

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/Utils/Arrays.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,10 @@ public static function pick(array &$array, string|int $key, mixed $default = nul
332332
/**
333333
* Tests whether at least one element in the array passes the test implemented by the
334334
* provided callback with signature `function ($value, $key, array $array): bool`.
335+
* @template K
336+
* @template V
337+
* @param iterable<K, V> $array
338+
* @param callable(V, K, ($array is array ? array<K, V> : iterable<K, V>)): bool $callback
335339
*/
336340
public static function some(iterable $array, callable $callback): bool
337341
{
@@ -348,6 +352,10 @@ public static function some(iterable $array, callable $callback): bool
348352
/**
349353
* Tests whether all elements in the array pass the test implemented by the provided function,
350354
* which has the signature `function ($value, $key, array $array): bool`.
355+
* @template K
356+
* @template V
357+
* @param iterable<K, V> $array
358+
* @param callable(V, K, ($array is array ? array<K, V> : iterable<K, V>)): bool $callback
351359
*/
352360
public static function every(iterable $array, callable $callback): bool
353361
{
@@ -364,6 +372,12 @@ public static function every(iterable $array, callable $callback): bool
364372
/**
365373
* Calls $callback on all elements in the array and returns the array of return values.
366374
* The callback has the signature `function ($value, $key, array $array): bool`.
375+
* @template K of array-key
376+
* @template V
377+
* @template R
378+
* @param iterable<K, V> $array
379+
* @param callable(V, K, ($array is array ? array<K, V> : iterable<K, V>)): R $callback
380+
* @return array<K, R>
367381
*/
368382
public static function map(iterable $array, callable $callback): array
369383
{

0 commit comments

Comments
 (0)