Skip to content

Commit

Permalink
Arrays: improved phpDoc
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jan 17, 2024
1 parent 9631bcf commit 662e524
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/Utils/Arrays.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public static function flatten(array $array, bool $preserveKeys = false): array
$res = [];
$cb = $preserveKeys
? function ($v, $k) use (&$res): void { $res[$k] = $v; }
: function ($v) use (&$res): void { $res[] = $v; };
: function ($v) use (&$res): void { $res[] = $v; };
array_walk_recursive($array, $cb);
return $res;
}
Expand Down Expand Up @@ -330,17 +330,17 @@ public static function pick(array &$array, string|int $key, mixed $default = nul


/**
* Tests whether at least one element in the array passes the test implemented by the
* provided callback with signature `function ($value, $key, array $array): bool`.
* Tests whether at least one element in the array passes the test implemented by the provided function,
* which has the signature `function ($value, $key, array $array): bool`.
* @template K
* @template V
* @param iterable<K, V> $array
* @param callable(V, K, ($array is array ? array<K, V> : iterable<K, V>)): bool $callback
* @param callable(V, K, ($array is array ? array<K, V> : iterable<K, V>)): bool $predicate
*/
public static function some(iterable $array, callable $callback): bool
public static function some(iterable $array, callable $predicate): bool
{
foreach ($array as $k => $v) {
if ($callback($v, $k, $array)) {
if ($predicate($v, $k, $array)) {
return true;
}
}
Expand All @@ -355,12 +355,12 @@ public static function some(iterable $array, callable $callback): bool
* @template K
* @template V
* @param iterable<K, V> $array
* @param callable(V, K, ($array is array ? array<K, V> : iterable<K, V>)): bool $callback
* @param callable(V, K, ($array is array ? array<K, V> : iterable<K, V>)): bool $predicate
*/
public static function every(iterable $array, callable $callback): bool
public static function every(iterable $array, callable $predicate): bool
{
foreach ($array as $k => $v) {
if (!$callback($v, $k, $array)) {
if (!$predicate($v, $k, $array)) {
return false;
}
}
Expand All @@ -370,20 +370,20 @@ public static function every(iterable $array, callable $callback): bool


/**
* Calls $callback on all elements in the array and returns the array of return values.
* The callback has the signature `function ($value, $key, array $array): bool`.
* Returns an array containing the original keys and results of applying the given transform function to each element.
* The function has signature `function ($value, $key, array $array): mixed`.
* @template K of array-key
* @template V
* @template R
* @param iterable<K, V> $array
* @param callable(V, K, ($array is array ? array<K, V> : iterable<K, V>)): R $callback
* @param callable(V, K, ($array is array ? array<K, V> : iterable<K, V>)): R $transformer
* @return array<K, R>
*/
public static function map(iterable $array, callable $callback): array
public static function map(iterable $array, callable $transformer): array
{
$res = [];
foreach ($array as $k => $v) {
$res[$k] = $callback($v, $k, $array);
$res[$k] = $transformer($v, $k, $array);
}

return $res;
Expand Down

0 comments on commit 662e524

Please sign in to comment.