update lock clucknut
All checks were successful
All checks were successful
This commit is contained in:
24
vendor/nette/utils/src/Utils/Iterables.php
vendored
24
vendor/nette/utils/src/Utils/Iterables.php
vendored
@@ -22,6 +22,7 @@ final class Iterables
|
||||
|
||||
/**
|
||||
* Tests for the presence of value.
|
||||
* @param iterable<mixed> $iterable
|
||||
*/
|
||||
public static function contains(iterable $iterable, mixed $value): bool
|
||||
{
|
||||
@@ -36,6 +37,7 @@ public static function contains(iterable $iterable, mixed $value): bool
|
||||
|
||||
/**
|
||||
* Tests for the presence of key.
|
||||
* @param iterable<mixed> $iterable
|
||||
*/
|
||||
public static function containsKey(iterable $iterable, mixed $key): bool
|
||||
{
|
||||
@@ -52,9 +54,11 @@ public static function containsKey(iterable $iterable, mixed $key): bool
|
||||
* Returns the first item (matching the specified predicate if given). If there is no such item, it returns result of invoking $else or null.
|
||||
* @template K
|
||||
* @template V
|
||||
* @template E
|
||||
* @param iterable<K, V> $iterable
|
||||
* @param ?callable(V, K, iterable<K, V>): bool $predicate
|
||||
* @return ?V
|
||||
* @param ?callable(): E $else
|
||||
* @return ($else is null ? ?V : V|E)
|
||||
*/
|
||||
public static function first(iterable $iterable, ?callable $predicate = null, ?callable $else = null): mixed
|
||||
{
|
||||
@@ -71,9 +75,11 @@ public static function first(iterable $iterable, ?callable $predicate = null, ?c
|
||||
* Returns the key of first item (matching the specified predicate if given). If there is no such item, it returns result of invoking $else or null.
|
||||
* @template K
|
||||
* @template V
|
||||
* @template E
|
||||
* @param iterable<K, V> $iterable
|
||||
* @param ?callable(V, K, iterable<K, V>): bool $predicate
|
||||
* @return ?K
|
||||
* @param ?callable(): E $else
|
||||
* @return ($else is null ? ?K : K|E)
|
||||
*/
|
||||
public static function firstKey(iterable $iterable, ?callable $predicate = null, ?callable $else = null): mixed
|
||||
{
|
||||
@@ -161,11 +167,11 @@ public static function map(iterable $iterable, callable $transformer): \Generato
|
||||
* Iterator that transforms keys and values by calling $transformer. If it returns null, the element is skipped.
|
||||
* @template K
|
||||
* @template V
|
||||
* @template ResV
|
||||
* @template ResK
|
||||
* @template ResV
|
||||
* @param iterable<K, V> $iterable
|
||||
* @param callable(V, K, iterable<K, V>): ?array{ResV, ResK} $transformer
|
||||
* @return \Generator<ResV, ResK>
|
||||
* @param callable(V, K, iterable<K, V>): ?array{ResK, ResV} $transformer
|
||||
* @return \Generator<ResK, ResV>
|
||||
*/
|
||||
public static function mapWithKeys(iterable $iterable, callable $transformer): \Generator
|
||||
{
|
||||
@@ -188,9 +194,10 @@ public static function mapWithKeys(iterable $iterable, callable $transformer): \
|
||||
*/
|
||||
public static function repeatable(callable $factory): \IteratorAggregate
|
||||
{
|
||||
return new class ($factory) implements \IteratorAggregate {
|
||||
return new class ($factory(...)) implements \IteratorAggregate {
|
||||
public function __construct(
|
||||
private $factory,
|
||||
/** @var \Closure(): iterable<mixed, mixed> */
|
||||
private \Closure $factory,
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -215,7 +222,8 @@ public static function memoize(iterable $iterable): \IteratorAggregate
|
||||
{
|
||||
return new class (self::toIterator($iterable)) implements \IteratorAggregate {
|
||||
public function __construct(
|
||||
private \Iterator $iterator,
|
||||
private readonly \Iterator $iterator,
|
||||
/** @var array<array{mixed, mixed}> */
|
||||
private array $cache = [],
|
||||
) {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user