| @@ 3184-3200 (lines=17) @@ | ||
| 3181 | * @psalm-return static<TKey,T> |
|
| 3182 | * @psalm-mutation-free |
|
| 3183 | */ |
|
| 3184 | public function indexBy($key): self |
|
| 3185 | { |
|
| 3186 | // init |
|
| 3187 | $results = []; |
|
| 3188 | ||
| 3189 | foreach ($this->getGenerator() as $a) { |
|
| 3190 | if (\array_key_exists($key, $a) === true) { |
|
| 3191 | $results[$a[$key]] = $a; |
|
| 3192 | } |
|
| 3193 | } |
|
| 3194 | ||
| 3195 | return static::create( |
|
| 3196 | $results, |
|
| 3197 | $this->iteratorClass, |
|
| 3198 | false |
|
| 3199 | ); |
|
| 3200 | } |
|
| 3201 | ||
| 3202 | /** |
|
| 3203 | * alias: for "Arrayy->searchIndex()" |
|
| @@ 4256-4273 (lines=18) @@ | ||
| 4253 | * @psalm-return static<TKey,T> |
|
| 4254 | * @psalm-mutation-free |
|
| 4255 | */ |
|
| 4256 | public function only(array $keys): self |
|
| 4257 | { |
|
| 4258 | $keys = \array_flip($keys); |
|
| 4259 | ||
| 4260 | $generator = function () use ($keys): \Generator { |
|
| 4261 | foreach ($this->getGenerator() as $key => $value) { |
|
| 4262 | if (isset($keys[$key])) { |
|
| 4263 | yield $key => $value; |
|
| 4264 | } |
|
| 4265 | } |
|
| 4266 | }; |
|
| 4267 | ||
| 4268 | return static::create( |
|
| 4269 | $generator, |
|
| 4270 | $this->iteratorClass, |
|
| 4271 | false |
|
| 4272 | ); |
|
| 4273 | } |
|
| 4274 | ||
| 4275 | /** |
|
| 4276 | * Pad array to the specified size with a given value. |
|