1616/**
1717 * @internal
1818 *
19- * @implements IteratorAggregate<mixed>
19+ * @template TKey
20+ * @template TValue
21+ *
22+ * @implements IteratorAggregate<TKey, TValue>
2023 */
2124final class IterableObject implements IteratorAggregate
2225{
23- /** @var iterable<mixed > */
26+ /** @var iterable<TKey, TValue > */
2427 private $ iterable ;
2528
26- /**
27- * @param iterable<mixed> $iterable
28- */
29+ /** @param iterable<TKey, TValue> $iterable */
2930 public function __construct (iterable $ iterable )
3031 {
3132 $ this ->iterable = $ iterable ;
3233 }
3334
35+ /**
36+ * @param (callable(TValue):bool)|null $filter
37+ *
38+ * @return self<TKey, TValue>
39+ */
3440 public function filter (?callable $ filter = null ): self
3541 {
3642 if ($ this ->iterable instanceof Traversable) {
@@ -48,6 +54,13 @@ static function ($value): bool {
4854 return new self ($ filtered );
4955 }
5056
57+ /**
58+ * @param callable(TValue):TResult $mapper
59+ *
60+ * @return self<TKey, TResult>
61+ *
62+ * @template TResult
63+ */
5164 public function map (callable $ mapper ): self
5265 {
5366 if ($ this ->iterable instanceof Traversable) {
@@ -57,15 +70,13 @@ public function map(callable $mapper): self
5770 return new self (array_map ($ mapper , $ this ->iterable ));
5871 }
5972
60- /**
61- * @return Traversable<mixed>
62- */
73+ /** @return Traversable<TKey, TValue> */
6374 public function getIterator (): Traversable
6475 {
6576 yield from $ this ->iterable ;
6677 }
6778
68- /** @return array<mixed > */
79+ /** @return array<array-key, TValue > */
6980 public function asArray (): array
7081 {
7182 return $ this ->iterable instanceof Traversable ? iterator_to_array ($ this ->iterable ) : $ this ->iterable ;
0 commit comments