Skip to content

Commit

Permalink
Arrays::some(), every(), map() for iteratos & Mapper should be replac…
Browse files Browse the repository at this point in the history
…ed by Iterators
  • Loading branch information
dg committed May 2, 2024
1 parent d3d796c commit fd325ea
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
3 changes: 1 addition & 2 deletions src/Iterators/Mapper.php
Expand Up @@ -10,9 +10,8 @@
namespace Nette\Iterators;



/**
* Applies the callback to the elements of the inner iterator.
* @deprecated use Nette\Utils\Iterables::map()
*/
class Mapper extends \IteratorIterator
{
Expand Down
22 changes: 11 additions & 11 deletions src/Utils/Arrays.php
Expand Up @@ -369,11 +369,11 @@ 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 function,
* which has the signature `function ($value, $key, array $array): bool`.
* @template K
* which has the signature `function (mixed $value, int|string $key, array $array): bool`.
* @template K of array-key
* @template V
* @param iterable<K, V> $array
* @param callable(V, K, ($array is array ? array<K, V> : iterable<K, V>)): bool $predicate
* @param array<K, V> $array
* @param callable(V, K, array<K, V>): bool $predicate
*/
public static function some(iterable $array, callable $predicate): bool
{
Expand All @@ -389,11 +389,11 @@ public static function some(iterable $array, callable $predicate): bool

/**
* Tests whether all elements in the array pass the test implemented by the provided function,
* which has the signature `function ($value, $key, array $array): bool`.
* @template K
* which has the signature `function (mixed $value, int|string $key, array $array): bool`.
* @template K of array-key
* @template V
* @param iterable<K, V> $array
* @param callable(V, K, ($array is array ? array<K, V> : iterable<K, V>)): bool $predicate
* @param array<K, V> $array
* @param callable(V, K, array<K, V>): bool $predicate
*/
public static function every(iterable $array, callable $predicate): bool
{
Expand Down Expand Up @@ -430,12 +430,12 @@ public static function filter(array $array, callable $predicate): array

/**
* 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`.
* The function has signature `function (mixed $value, int|string $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 $transformer
* @param array<K, V> $array
* @param callable(V, K, array<K, V>): R $transformer
* @return array<K, R>
*/
public static function map(iterable $array, callable $transformer): array
Expand Down

0 comments on commit fd325ea

Please sign in to comment.