| @@ 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. |
|
| @@ 4733-4757 (lines=25) @@ | ||
| 4730 | * @psalm-return static<TKey,T> |
|
| 4731 | * @psalm-mutation-free |
|
| 4732 | */ |
|
| 4733 | public function prependImmutable($value, $key = null) |
|
| 4734 | { |
|
| 4735 | $generator = function () use ($key, $value): \Generator { |
|
| 4736 | if ($this->properties !== []) { |
|
| 4737 | $this->checkType($key, $value); |
|
| 4738 | } |
|
| 4739 | ||
| 4740 | if ($key !== null) { |
|
| 4741 | yield $key => $value; |
|
| 4742 | } else { |
|
| 4743 | yield $value; |
|
| 4744 | } |
|
| 4745 | ||
| 4746 | /** @noinspection YieldFromCanBeUsedInspection - FP */ |
|
| 4747 | foreach ($this->getGenerator() as $keyOld => $itemOld) { |
|
| 4748 | yield $keyOld => $itemOld; |
|
| 4749 | } |
|
| 4750 | }; |
|
| 4751 | ||
| 4752 | return static::create( |
|
| 4753 | $generator, |
|
| 4754 | $this->iteratorClass, |
|
| 4755 | false |
|
| 4756 | ); |
|
| 4757 | } |
|
| 4758 | ||
| 4759 | /** |
|
| 4760 | * Add a suffix to each key. |
|