| @@ 974-992 (lines=19) @@ | ||
| 971 | * @psalm-return static<TKey,T> |
|
| 972 | * @psalm-mutation-free |
|
| 973 | */ |
|
| 974 | public function appendToEachKey($prefix): self |
|
| 975 | { |
|
| 976 | // init |
|
| 977 | $result = []; |
|
| 978 | ||
| 979 | foreach ($this->getGenerator() as $key => $item) { |
|
| 980 | if ($item instanceof self) { |
|
| 981 | $result[$prefix . $key] = $item->appendToEachKey($prefix); |
|
| 982 | } elseif (\is_array($item) === true) { |
|
| 983 | $result[$prefix . $key] = self::create($item, $this->iteratorClass, false) |
|
| 984 | ->appendToEachKey($prefix) |
|
| 985 | ->toArray(); |
|
| 986 | } else { |
|
| 987 | $result[$prefix . $key] = $item; |
|
| 988 | } |
|
| 989 | } |
|
| 990 | ||
| 991 | return self::create($result, $this->iteratorClass, false); |
|
| 992 | } |
|
| 993 | ||
| 994 | /** |
|
| 995 | * Add a prefix to each value. |
|
| @@ 4330-4355 (lines=26) @@ | ||
| 4327 | * @psalm-return static<TKey,T> |
|
| 4328 | * @psalm-mutation-free |
|
| 4329 | */ |
|
| 4330 | public function prependToEachKey($suffix): self |
|
| 4331 | { |
|
| 4332 | // init |
|
| 4333 | $result = []; |
|
| 4334 | ||
| 4335 | foreach ($this->getGenerator() as $key => $item) { |
|
| 4336 | if ($item instanceof self) { |
|
| 4337 | $result[$key] = $item->prependToEachKey($suffix); |
|
| 4338 | } elseif (\is_array($item) === true) { |
|
| 4339 | $result[$key] = self::create( |
|
| 4340 | $item, |
|
| 4341 | $this->iteratorClass, |
|
| 4342 | false |
|
| 4343 | )->prependToEachKey($suffix) |
|
| 4344 | ->toArray(); |
|
| 4345 | } else { |
|
| 4346 | $result[$key . $suffix] = $item; |
|
| 4347 | } |
|
| 4348 | } |
|
| 4349 | ||
| 4350 | return self::create( |
|
| 4351 | $result, |
|
| 4352 | $this->iteratorClass, |
|
| 4353 | false |
|
| 4354 | ); |
|
| 4355 | } |
|
| 4356 | ||
| 4357 | /** |
|
| 4358 | * Add a suffix to each value. |
|