@@ 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()" |
|
@@ 4496-4513 (lines=18) @@ | ||
4493 | * @psalm-return static<TKey,T> |
|
4494 | * @psalm-mutation-free |
|
4495 | */ |
|
4496 | public function only(array $keys): self |
|
4497 | { |
|
4498 | $keys = \array_flip($keys); |
|
4499 | ||
4500 | $generator = function () use ($keys): \Generator { |
|
4501 | foreach ($this->getGenerator() as $key => $value) { |
|
4502 | if (isset($keys[$key])) { |
|
4503 | yield $key => $value; |
|
4504 | } |
|
4505 | } |
|
4506 | }; |
|
4507 | ||
4508 | return static::create( |
|
4509 | $generator, |
|
4510 | $this->iteratorClass, |
|
4511 | false |
|
4512 | ); |
|
4513 | } |
|
4514 | ||
4515 | /** |
|
4516 | * Pad array to the specified size with a given value. |