From 3e19d4598ac1175cfda6c44da7f5a1b5b1ee5a49 Mon Sep 17 00:00:00 2001 From: Anna Damm Date: Mon, 11 May 2026 21:20:32 +0200 Subject: [PATCH 1/3] add iterable key to type hints --- src/iter.php | 68 +++++++++++++++++++++++++++++----------------------- 1 file changed, 38 insertions(+), 30 deletions(-) diff --git a/src/iter.php b/src/iter.php index 0d487b4..813a248 100644 --- a/src/iter.php +++ b/src/iter.php @@ -71,13 +71,14 @@ function range($start, $end, $step = null): \Iterator { * * $column = map(iter\func\index('name'), $iter); * - * @template T - * @template U + * @template IterableValue + * @template FunctionReturn + * @template IterableKey * - * @param callable(T):U $function Mapping function - * @param iterable $iterable Iterable to be mapped over + * @param callable(IterableValue):FunctionReturn $function Mapping function + * @param iterable $iterable Iterable to be mapped over * - * @return \Iterator + * @return \Iterator */ function map(callable $function, iterable $iterable): \Iterator { foreach ($iterable as $key => $value) { @@ -243,12 +244,13 @@ function apply(callable $function, iterable $iterable): void { * * iter\filter(iter\func\operator('instanceof', 'SomeClass'), $objects); * - * @template T + * @template TKey + * @template TValue * - * @param callable(T):bool $predicate Predicate function - * @param iterable $iterable Iterable to filter + * @param callable(TValue):bool $predicate Predicate function + * @param iterable $iterable Iterable to filter * - * @return \Iterator + * @return \Iterator */ function filter(callable $predicate, iterable $iterable): \Iterator { foreach ($iterable as $key => $value) { @@ -465,11 +467,12 @@ function zipKeyValue(iterable $keys, iterable $values): \Iterator { * iter\chain(iter\range(0, 5), iter\range(6, 10), iter\range(11, 15)) * => iter(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15) * - * @template T + * @template TKey + * @template TValue * - * @param iterable ...$iterables Iterables to chain + * @param iterable ...$iterables Iterables to chain * - * @return \Iterator + * @return \Iterator */ function chain(iterable ...$iterables): \Iterator { foreach ($iterables as $iterable) { @@ -492,7 +495,7 @@ function chain(iterable ...$iterables): \Iterator { * * @param iterable ...$iterables Iterables to combine * - * @return \Iterator + * @return \Iterator */ function product(iterable ...$iterables): \Iterator { $iterators = array_map('iter\\toIter', $iterables); @@ -539,14 +542,15 @@ function product(iterable ...$iterables): \Iterator { * iter\slice([-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5], 5, 3) * => iter(0, 1, 2, 3) * - * @template T + * @template TKey + * @template TValue * - * @param iterable $iterable Iterable to take the slice from + * @param iterable $iterable Iterable to take the slice from * @param int $start Start offset * @param int $length Length (if not specified all remaining values from the * iterable are used) * - * @return \Iterator + * @return \Iterator */ function slice(iterable $iterable, int $start, $length = PHP_INT_MAX): \Iterator { if ($start < 0) { @@ -579,12 +583,13 @@ function slice(iterable $iterable, int $start, $length = PHP_INT_MAX): \Iterator * iter\take(3, [1, 2, 3, 4, 5]) * => iter(1, 2, 3) * - * @template T + * @template TKey + * @template TValue * * @param int $num Number of elements to take from the start - * @param iterable $iterable Iterable to take the elements from + * @param iterable $iterable Iterable to take the elements from * - * @return \Iterator + * @return \Iterator */ function take(int $num, iterable $iterable): \Iterator { return slice($iterable, 0, $num); @@ -598,12 +603,13 @@ function take(int $num, iterable $iterable): \Iterator { * iter\drop(3, [1, 2, 3, 4, 5]) * => iter(4, 5) * - * @template T + * @template TKey + * @template TValue * * @param int $num Number of elements to drop from the start - * @param iterable $iterable Iterable to drop the elements from + * @param iterable $iterable Iterable to drop the elements from * - * @return \Iterator + * @return \Iterator */ function drop(int $num, iterable $iterable): \Iterator { return slice($iterable, $num); @@ -782,12 +788,13 @@ function search(callable $predicate, iterable $iterable) { * iter\takeWhile(iter\func\operator('>', 0), [3, 1, 4, -1, 5]) * => iter(3, 1, 4) * - * @template T + * @template TKey + * @template TValue * - * @param callable(T):bool $predicate Predicate function - * @param iterable $iterable Iterable to take values from + * @param callable(TValue):bool $predicate Predicate function + * @param iterable $iterable Iterable to take values from * - * @return \Iterator + * @return \Iterator */ function takeWhile(callable $predicate, iterable $iterable): \Iterator { foreach ($iterable as $key => $value) { @@ -810,12 +817,13 @@ function takeWhile(callable $predicate, iterable $iterable): \Iterator { * iter\dropWhile(iter\func\operator('>', 0), [3, 1, 4, -1, 5]) * => iter(-1, 5) * - * @template T + * @template TKey + * @template TValue * - * @param callable(T):bool $predicate Predicate function - * @param iterable $iterable Iterable to drop values from + * @param callable(TValue):bool $predicate Predicate function + * @param iterable $iterable Iterable to drop values from * - * @return \Iterator + * @return \Iterator */ function dropWhile(callable $predicate, iterable $iterable): \Iterator { $failed = false; From 620879a2292e275c12cd9158344b53ddc381d955 Mon Sep 17 00:00:00 2001 From: Anna Damm Date: Mon, 11 May 2026 21:20:52 +0200 Subject: [PATCH 2/3] fix phpstan not recognizing template parameter types --- src/iter.rewindable.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/iter.rewindable.php b/src/iter.rewindable.php index 451accf..5fa9ef9 100644 --- a/src/iter.rewindable.php +++ b/src/iter.rewindable.php @@ -17,9 +17,9 @@ * @template TKey * @template TValue * - * @param callable(...mixed):\Iterator $function Iterator factory function + * @param callable():\Iterator $function Iterator factory function * - * @return callable(...mixed):\Iterator Rewindable iterator factory function + * @return callable():\Iterator Rewindable iterator factory function */ function makeRewindable(callable $function) { return function(...$args) use ($function) { @@ -43,7 +43,7 @@ function makeRewindable(callable $function) { * @template TKey * @template TValue * - * @param callable(...mixed):\Iterator $function Iterator factory function + * @param callable():\Iterator $function Iterator factory function * @param mixed ...$args Function arguments * * @return \Iterator Rewindable generator result From e595bcddd2d30f16e2ae3c33cafcea23834c873b Mon Sep 17 00:00:00 2001 From: Anna Damm Date: Mon, 11 May 2026 21:21:09 +0200 Subject: [PATCH 3/3] add new versions of psalm and phpstan to dev requirements --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index cfd04c4..6849e4e 100644 --- a/composer.json +++ b/composer.json @@ -18,8 +18,8 @@ }, "require-dev": { "phpunit/phpunit": "^7.0 || ^8.0 || ^9.0", - "vimeo/psalm": "^4.18 || ^5.13", - "phpstan/phpstan": "^1.4" + "vimeo/psalm": "^4.18 || ^5.13 || ^6.16", + "phpstan/phpstan": "^1.4 || ^2.1" }, "autoload": { "files": [