| @@ 308-332 (lines=25) @@ | ||
| 305 | * @psalm-return static<TKey,T> |
|
| 306 | * @psalm-mutation-free |
|
| 307 | */ |
|
| 308 | public function appendImmutable($value, $key = null): self |
|
| 309 | { |
|
| 310 | $generator = function () use ($key, $value): \Generator { |
|
| 311 | if ($this->properties !== []) { |
|
| 312 | $this->checkType($key, $value); |
|
| 313 | } |
|
| 314 | ||
| 315 | /** @noinspection YieldFromCanBeUsedInspection - FP */ |
|
| 316 | foreach ($this->getGenerator() as $keyOld => $itemOld) { |
|
| 317 | yield $keyOld => $itemOld; |
|
| 318 | } |
|
| 319 | ||
| 320 | if ($key !== null) { |
|
| 321 | yield $key => $value; |
|
| 322 | } else { |
|
| 323 | yield $value; |
|
| 324 | } |
|
| 325 | }; |
|
| 326 | ||
| 327 | return static::create( |
|
| 328 | $generator, |
|
| 329 | $this->iteratorClass, |
|
| 330 | false |
|
| 331 | ); |
|
| 332 | } |
|
| 333 | ||
| 334 | /** |
|
| 335 | * Sort the entries by value. |
|
| @@ 4747-4771 (lines=25) @@ | ||
| 4744 | * @psalm-return static<TKey,T> |
|
| 4745 | * @psalm-mutation-free |
|
| 4746 | */ |
|
| 4747 | public function prependImmutable($value, $key = null) |
|
| 4748 | { |
|
| 4749 | $generator = function () use ($key, $value): \Generator { |
|
| 4750 | if ($this->properties !== []) { |
|
| 4751 | $this->checkType($key, $value); |
|
| 4752 | } |
|
| 4753 | ||
| 4754 | if ($key !== null) { |
|
| 4755 | yield $key => $value; |
|
| 4756 | } else { |
|
| 4757 | yield $value; |
|
| 4758 | } |
|
| 4759 | ||
| 4760 | /** @noinspection YieldFromCanBeUsedInspection - FP */ |
|
| 4761 | foreach ($this->getGenerator() as $keyOld => $itemOld) { |
|
| 4762 | yield $keyOld => $itemOld; |
|
| 4763 | } |
|
| 4764 | }; |
|
| 4765 | ||
| 4766 | return static::create( |
|
| 4767 | $generator, |
|
| 4768 | $this->iteratorClass, |
|
| 4769 | false |
|
| 4770 | ); |
|
| 4771 | } |
|
| 4772 | ||
| 4773 | /** |
|
| 4774 | * Add a suffix to each key. |
|