| @@ 3131-3147 (lines=17) @@ | ||
| 3128 | * @psalm-return static<TKey,T> |
|
| 3129 | * @psalm-mutation-free |
|
| 3130 | */ |
|
| 3131 | public function indexBy($key): self |
|
| 3132 | { |
|
| 3133 | // init |
|
| 3134 | $results = []; |
|
| 3135 | ||
| 3136 | foreach ($this->getGenerator() as $a) { |
|
| 3137 | if (\array_key_exists($key, $a) === true) { |
|
| 3138 | $results[$a[$key]] = $a; |
|
| 3139 | } |
|
| 3140 | } |
|
| 3141 | ||
| 3142 | return static::create( |
|
| 3143 | $results, |
|
| 3144 | $this->iteratorClass, |
|
| 3145 | false |
|
| 3146 | ); |
|
| 3147 | } |
|
| 3148 | ||
| 3149 | /** |
|
| 3150 | * alias: for "Arrayy->searchIndex()" |
|
| @@ 4203-4220 (lines=18) @@ | ||
| 4200 | * @psalm-return static<TKey,T> |
|
| 4201 | * @psalm-mutation-free |
|
| 4202 | */ |
|
| 4203 | public function only(array $keys): self |
|
| 4204 | { |
|
| 4205 | $keys = \array_flip($keys); |
|
| 4206 | ||
| 4207 | $generator = function () use ($keys): \Generator { |
|
| 4208 | foreach ($this->getGenerator() as $key => $value) { |
|
| 4209 | if (isset($keys[$key])) { |
|
| 4210 | yield $key => $value; |
|
| 4211 | } |
|
| 4212 | } |
|
| 4213 | }; |
|
| 4214 | ||
| 4215 | return static::create( |
|
| 4216 | $generator, |
|
| 4217 | $this->iteratorClass, |
|
| 4218 | false |
|
| 4219 | ); |
|
| 4220 | } |
|
| 4221 | ||
| 4222 | /** |
|
| 4223 | * Pad array to the specified size with a given value. |
|