| @@ 3432-3448 (lines=17) @@ | ||
| 3429 | * @psalm-return static<TKey,T> |
|
| 3430 | * @psalm-mutation-free |
|
| 3431 | */ |
|
| 3432 | public function indexBy($key): self |
|
| 3433 | { |
|
| 3434 | // init |
|
| 3435 | $results = []; |
|
| 3436 | ||
| 3437 | foreach ($this->getGenerator() as $a) { |
|
| 3438 | if (\array_key_exists($key, $a) === true) { |
|
| 3439 | $results[$a[$key]] = $a; |
|
| 3440 | } |
|
| 3441 | } |
|
| 3442 | ||
| 3443 | return static::create( |
|
| 3444 | $results, |
|
| 3445 | $this->iteratorClass, |
|
| 3446 | false |
|
| 3447 | ); |
|
| 3448 | } |
|
| 3449 | ||
| 3450 | /** |
|
| 3451 | * alias: for "Arrayy->searchIndex()" |
|
| @@ 4615-4632 (lines=18) @@ | ||
| 4612 | * @psalm-return static<TKey,T> |
|
| 4613 | * @psalm-mutation-free |
|
| 4614 | */ |
|
| 4615 | public function only(array $keys): self |
|
| 4616 | { |
|
| 4617 | $keys = \array_flip($keys); |
|
| 4618 | ||
| 4619 | $generator = function () use ($keys): \Generator { |
|
| 4620 | foreach ($this->getGenerator() as $key => $value) { |
|
| 4621 | if (isset($keys[$key])) { |
|
| 4622 | yield $key => $value; |
|
| 4623 | } |
|
| 4624 | } |
|
| 4625 | }; |
|
| 4626 | ||
| 4627 | return static::create( |
|
| 4628 | $generator, |
|
| 4629 | $this->iteratorClass, |
|
| 4630 | false |
|
| 4631 | ); |
|
| 4632 | } |
|
| 4633 | ||
| 4634 | /** |
|
| 4635 | * Pad array to the specified size with a given value. |
|