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