| @@ 3422-3438 (lines=17) @@ | ||
| 3419 | * @psalm-return static<TKey,T> | |
| 3420 | * @psalm-mutation-free | |
| 3421 | */ | |
| 3422 | public function indexBy($key): self | |
| 3423 |     { | |
| 3424 | // init | |
| 3425 | $results = []; | |
| 3426 | ||
| 3427 |         foreach ($this->getGenerator() as $a) { | |
| 3428 |             if (\array_key_exists($key, $a) === true) { | |
| 3429 | $results[$a[$key]] = $a; | |
| 3430 | } | |
| 3431 | } | |
| 3432 | ||
| 3433 | return static::create( | |
| 3434 | $results, | |
| 3435 | $this->iteratorClass, | |
| 3436 | false | |
| 3437 | ); | |
| 3438 | } | |
| 3439 | ||
| 3440 | /** | |
| 3441 | * alias: for "Arrayy->searchIndex()" | |
| @@ 4601-4618 (lines=18) @@ | ||
| 4598 | * @psalm-return static<TKey,T> | |
| 4599 | * @psalm-mutation-free | |
| 4600 | */ | |
| 4601 | public function only(array $keys): self | |
| 4602 |     { | |
| 4603 | $keys = \array_flip($keys); | |
| 4604 | ||
| 4605 |         $generator = function () use ($keys): \Generator { | |
| 4606 |             foreach ($this->getGenerator() as $key => $value) { | |
| 4607 |                 if (isset($keys[$key])) { | |
| 4608 | yield $key => $value; | |
| 4609 | } | |
| 4610 | } | |
| 4611 | }; | |
| 4612 | ||
| 4613 | return static::create( | |
| 4614 | $generator, | |
| 4615 | $this->iteratorClass, | |
| 4616 | false | |
| 4617 | ); | |
| 4618 | } | |
| 4619 | ||
| 4620 | /** | |
| 4621 | * Pad array to the specified size with a given value. | |