| @@ 3507-3523 (lines=17) @@ | ||
| 3504 | * @psalm-return static<TKey,T> |
|
| 3505 | * @psalm-mutation-free |
|
| 3506 | */ |
|
| 3507 | public function indexBy($key): self |
|
| 3508 | { |
|
| 3509 | // init |
|
| 3510 | $results = []; |
|
| 3511 | ||
| 3512 | foreach ($this->getGenerator() as $a) { |
|
| 3513 | if (\array_key_exists($key, $a) === true) { |
|
| 3514 | $results[$a[$key]] = $a; |
|
| 3515 | } |
|
| 3516 | } |
|
| 3517 | ||
| 3518 | return static::create( |
|
| 3519 | $results, |
|
| 3520 | $this->iteratorClass, |
|
| 3521 | false |
|
| 3522 | ); |
|
| 3523 | } |
|
| 3524 | ||
| 3525 | /** |
|
| 3526 | * alias: for "Arrayy->searchIndex()" |
|
| @@ 4710-4727 (lines=18) @@ | ||
| 4707 | * @psalm-return static<TKey,T> |
|
| 4708 | * @psalm-mutation-free |
|
| 4709 | */ |
|
| 4710 | public function only(array $keys): self |
|
| 4711 | { |
|
| 4712 | $keys = \array_flip($keys); |
|
| 4713 | ||
| 4714 | $generator = function () use ($keys): \Generator { |
|
| 4715 | foreach ($this->getGenerator() as $key => $value) { |
|
| 4716 | if (isset($keys[$key])) { |
|
| 4717 | yield $key => $value; |
|
| 4718 | } |
|
| 4719 | } |
|
| 4720 | }; |
|
| 4721 | ||
| 4722 | return static::create( |
|
| 4723 | $generator, |
|
| 4724 | $this->iteratorClass, |
|
| 4725 | false |
|
| 4726 | ); |
|
| 4727 | } |
|
| 4728 | ||
| 4729 | /** |
|
| 4730 | * Pad array to the specified size with a given value. |
|