| @@ 3317-3333 (lines=17) @@ | ||
| 3314 | * @psalm-return static<TKey,T> |
|
| 3315 | * @psalm-mutation-free |
|
| 3316 | */ |
|
| 3317 | public function indexBy($key): self |
|
| 3318 | { |
|
| 3319 | // init |
|
| 3320 | $results = []; |
|
| 3321 | ||
| 3322 | foreach ($this->getGenerator() as $a) { |
|
| 3323 | if (\array_key_exists($key, $a) === true) { |
|
| 3324 | $results[$a[$key]] = $a; |
|
| 3325 | } |
|
| 3326 | } |
|
| 3327 | ||
| 3328 | return static::create( |
|
| 3329 | $results, |
|
| 3330 | $this->iteratorClass, |
|
| 3331 | false |
|
| 3332 | ); |
|
| 3333 | } |
|
| 3334 | ||
| 3335 | /** |
|
| 3336 | * alias: for "Arrayy->searchIndex()" |
|
| @@ 4480-4497 (lines=18) @@ | ||
| 4477 | * @psalm-return static<TKey,T> |
|
| 4478 | * @psalm-mutation-free |
|
| 4479 | */ |
|
| 4480 | public function only(array $keys): self |
|
| 4481 | { |
|
| 4482 | $keys = \array_flip($keys); |
|
| 4483 | ||
| 4484 | $generator = function () use ($keys): \Generator { |
|
| 4485 | foreach ($this->getGenerator() as $key => $value) { |
|
| 4486 | if (isset($keys[$key])) { |
|
| 4487 | yield $key => $value; |
|
| 4488 | } |
|
| 4489 | } |
|
| 4490 | }; |
|
| 4491 | ||
| 4492 | return static::create( |
|
| 4493 | $generator, |
|
| 4494 | $this->iteratorClass, |
|
| 4495 | false |
|
| 4496 | ); |
|
| 4497 | } |
|
| 4498 | ||
| 4499 | /** |
|
| 4500 | * Pad array to the specified size with a given value. |
|