| @@ 326-350 (lines=25) @@ | ||
| 323 | * @phpstan-return static<TKey,T> |
|
| 324 | * @psalm-mutation-free |
|
| 325 | */ |
|
| 326 | public function appendImmutable($value, $key = null): self |
|
| 327 | { |
|
| 328 | /** |
|
| 329 | * @phpstan-return \Generator<TKey,T> $generator |
|
| 330 | */ |
|
| 331 | $generator = function () use ($key, $value): \Generator { |
|
| 332 | if ($this->properties !== []) { |
|
| 333 | $this->checkType($key, $value); |
|
| 334 | } |
|
| 335 | ||
| 336 | foreach ($this->getGenerator() as $keyOld => $itemOld) { |
|
| 337 | yield $keyOld => $itemOld; |
|
| 338 | } |
|
| 339 | ||
| 340 | if ($key !== null) { |
|
| 341 | yield $key => $value; |
|
| 342 | } else { |
|
| 343 | yield $value; |
|
| 344 | } |
|
| 345 | }; |
|
| 346 | ||
| 347 | return static::create( |
|
| 348 | $generator, |
|
| 349 | $this->iteratorClass, |
|
| 350 | false |
|
| 351 | ); |
|
| 352 | } |
|
| 353 | ||
| @@ 4951-4975 (lines=25) @@ | ||
| 4948 | * @phpstan-return static<TKey,T> |
|
| 4949 | * @psalm-mutation-free |
|
| 4950 | */ |
|
| 4951 | public function prependImmutable($value, $key = null) |
|
| 4952 | { |
|
| 4953 | $generator = function () use ($key, $value): \Generator { |
|
| 4954 | if ($this->properties !== []) { |
|
| 4955 | $this->checkType($key, $value); |
|
| 4956 | } |
|
| 4957 | ||
| 4958 | if ($key !== null) { |
|
| 4959 | yield $key => $value; |
|
| 4960 | } else { |
|
| 4961 | yield $value; |
|
| 4962 | } |
|
| 4963 | ||
| 4964 | foreach ($this->getGenerator() as $keyOld => $itemOld) { |
|
| 4965 | yield $keyOld => $itemOld; |
|
| 4966 | } |
|
| 4967 | }; |
|
| 4968 | ||
| 4969 | return static::create( |
|
| 4970 | $generator, |
|
| 4971 | $this->iteratorClass, |
|
| 4972 | false |
|
| 4973 | ); |
|
| 4974 | } |
|
| 4975 | ||
| 4976 | /** |
|
| 4977 | * Add a suffix to each key. |
|
| 4978 | * |
|