| @@ 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()" |
|
| @@ 4605-4622 (lines=18) @@ | ||
| 4602 | * @psalm-return static<TKey,T> |
|
| 4603 | * @psalm-mutation-free |
|
| 4604 | */ |
|
| 4605 | public function only(array $keys): self |
|
| 4606 | { |
|
| 4607 | $keys = \array_flip($keys); |
|
| 4608 | ||
| 4609 | $generator = function () use ($keys): \Generator { |
|
| 4610 | foreach ($this->getGenerator() as $key => $value) { |
|
| 4611 | if (isset($keys[$key])) { |
|
| 4612 | yield $key => $value; |
|
| 4613 | } |
|
| 4614 | } |
|
| 4615 | }; |
|
| 4616 | ||
| 4617 | return static::create( |
|
| 4618 | $generator, |
|
| 4619 | $this->iteratorClass, |
|
| 4620 | false |
|
| 4621 | ); |
|
| 4622 | } |
|
| 4623 | ||
| 4624 | /** |
|
| 4625 | * Pad array to the specified size with a given value. |
|