@@ 3441-3457 (lines=17) @@ | ||
3438 | * @psalm-return static<TKey,T> |
|
3439 | * @psalm-mutation-free |
|
3440 | */ |
|
3441 | public function indexBy($key): self |
|
3442 | { |
|
3443 | // init |
|
3444 | $results = []; |
|
3445 | ||
3446 | foreach ($this->getGenerator() as $a) { |
|
3447 | if (\array_key_exists($key, $a) === true) { |
|
3448 | $results[$a[$key]] = $a; |
|
3449 | } |
|
3450 | } |
|
3451 | ||
3452 | return static::create( |
|
3453 | $results, |
|
3454 | $this->iteratorClass, |
|
3455 | false |
|
3456 | ); |
|
3457 | } |
|
3458 | ||
3459 | /** |
|
3460 | * alias: for "Arrayy->searchIndex()" |
|
@@ 4632-4649 (lines=18) @@ | ||
4629 | * @psalm-return static<TKey,T> |
|
4630 | * @psalm-mutation-free |
|
4631 | */ |
|
4632 | public function only(array $keys): self |
|
4633 | { |
|
4634 | $keys = \array_flip($keys); |
|
4635 | ||
4636 | $generator = function () use ($keys): \Generator { |
|
4637 | foreach ($this->getGenerator() as $key => $value) { |
|
4638 | if (isset($keys[$key])) { |
|
4639 | yield $key => $value; |
|
4640 | } |
|
4641 | } |
|
4642 | }; |
|
4643 | ||
4644 | return static::create( |
|
4645 | $generator, |
|
4646 | $this->iteratorClass, |
|
4647 | false |
|
4648 | ); |
|
4649 | } |
|
4650 | ||
4651 | /** |
|
4652 | * Pad array to the specified size with a given value. |