| @@ 3548-3564 (lines=17) @@ | ||
| 3545 | * @phpstan-return static<TKey,T> |
|
| 3546 | * @psalm-mutation-free |
|
| 3547 | */ |
|
| 3548 | public function indexBy($key): self |
|
| 3549 | { |
|
| 3550 | // init |
|
| 3551 | $results = []; |
|
| 3552 | ||
| 3553 | foreach ($this->getGenerator() as $a) { |
|
| 3554 | if (\array_key_exists($key, $a) === true) { |
|
| 3555 | $results[$a[$key]] = $a; |
|
| 3556 | } |
|
| 3557 | } |
|
| 3558 | ||
| 3559 | return static::create( |
|
| 3560 | $results, |
|
| 3561 | $this->iteratorClass, |
|
| 3562 | false |
|
| 3563 | ); |
|
| 3564 | } |
|
| 3565 | ||
| 3566 | /** |
|
| 3567 | * alias: for "Arrayy->searchIndex()" |
|
| @@ 4759-4776 (lines=18) @@ | ||
| 4756 | * @phpstan-return static<TKey,T> |
|
| 4757 | * @psalm-mutation-free |
|
| 4758 | */ |
|
| 4759 | public function only(array $keys): self |
|
| 4760 | { |
|
| 4761 | $keys = \array_flip($keys); |
|
| 4762 | ||
| 4763 | $generator = function () use ($keys): \Generator { |
|
| 4764 | foreach ($this->getGenerator() as $key => $value) { |
|
| 4765 | if (isset($keys[$key])) { |
|
| 4766 | yield $key => $value; |
|
| 4767 | } |
|
| 4768 | } |
|
| 4769 | }; |
|
| 4770 | ||
| 4771 | return static::create( |
|
| 4772 | $generator, |
|
| 4773 | $this->iteratorClass, |
|
| 4774 | false |
|
| 4775 | ); |
|
| 4776 | } |
|
| 4777 | ||
| 4778 | /** |
|
| 4779 | * Pad array to the specified size with a given value. |
|