| @@ 318-342 (lines=25) @@ | ||
| 315 | * @psalm-return static<TKey,T> |
|
| 316 | * @psalm-mutation-free |
|
| 317 | */ |
|
| 318 | public function appendImmutable($value, $key = null): self |
|
| 319 | { |
|
| 320 | $generator = function () use ($key, $value): \Generator { |
|
| 321 | if ($this->properties !== []) { |
|
| 322 | $this->checkType($key, $value); |
|
| 323 | } |
|
| 324 | ||
| 325 | /** @noinspection YieldFromCanBeUsedInspection - FP */ |
|
| 326 | foreach ($this->getGenerator() as $keyOld => $itemOld) { |
|
| 327 | yield $keyOld => $itemOld; |
|
| 328 | } |
|
| 329 | ||
| 330 | if ($key !== null) { |
|
| 331 | yield $key => $value; |
|
| 332 | } else { |
|
| 333 | yield $value; |
|
| 334 | } |
|
| 335 | }; |
|
| 336 | ||
| 337 | return static::create( |
|
| 338 | $generator, |
|
| 339 | $this->iteratorClass, |
|
| 340 | false |
|
| 341 | ); |
|
| 342 | } |
|
| 343 | ||
| 344 | /** |
|
| 345 | * Sort the entries by value. |
|
| @@ 4846-4870 (lines=25) @@ | ||
| 4843 | * @psalm-return static<TKey,T> |
|
| 4844 | * @psalm-mutation-free |
|
| 4845 | */ |
|
| 4846 | public function prependImmutable($value, $key = null) |
|
| 4847 | { |
|
| 4848 | $generator = function () use ($key, $value): \Generator { |
|
| 4849 | if ($this->properties !== []) { |
|
| 4850 | $this->checkType($key, $value); |
|
| 4851 | } |
|
| 4852 | ||
| 4853 | if ($key !== null) { |
|
| 4854 | yield $key => $value; |
|
| 4855 | } else { |
|
| 4856 | yield $value; |
|
| 4857 | } |
|
| 4858 | ||
| 4859 | /** @noinspection YieldFromCanBeUsedInspection - FP */ |
|
| 4860 | foreach ($this->getGenerator() as $keyOld => $itemOld) { |
|
| 4861 | yield $keyOld => $itemOld; |
|
| 4862 | } |
|
| 4863 | }; |
|
| 4864 | ||
| 4865 | return static::create( |
|
| 4866 | $generator, |
|
| 4867 | $this->iteratorClass, |
|
| 4868 | false |
|
| 4869 | ); |
|
| 4870 | } |
|
| 4871 | ||
| 4872 | /** |
|
| 4873 | * Add a suffix to each key. |
|