| @@ 957-975 (lines=19) @@ | ||
| 954 | * @psalm-return static<TKey,T> |
|
| 955 | * @psalm-mutation-free |
|
| 956 | */ |
|
| 957 | public function appendToEachKey($prefix): self |
|
| 958 | { |
|
| 959 | // init |
|
| 960 | $result = []; |
|
| 961 | ||
| 962 | foreach ($this->getGenerator() as $key => $item) { |
|
| 963 | if ($item instanceof self) { |
|
| 964 | $result[$prefix . $key] = $item->appendToEachKey($prefix); |
|
| 965 | } elseif (\is_array($item) === true) { |
|
| 966 | $result[$prefix . $key] = self::create($item, $this->iteratorClass, false) |
|
| 967 | ->appendToEachKey($prefix) |
|
| 968 | ->toArray(); |
|
| 969 | } else { |
|
| 970 | $result[$prefix . $key] = $item; |
|
| 971 | } |
|
| 972 | } |
|
| 973 | ||
| 974 | return self::create($result, $this->iteratorClass, false); |
|
| 975 | } |
|
| 976 | ||
| 977 | /** |
|
| 978 | * Add a prefix to each value. |
|
| @@ 4193-4218 (lines=26) @@ | ||
| 4190 | * @psalm-return static<TKey,T> |
|
| 4191 | * @psalm-mutation-free |
|
| 4192 | */ |
|
| 4193 | public function prependToEachKey($suffix): self |
|
| 4194 | { |
|
| 4195 | // init |
|
| 4196 | $result = []; |
|
| 4197 | ||
| 4198 | foreach ($this->getGenerator() as $key => $item) { |
|
| 4199 | if ($item instanceof self) { |
|
| 4200 | $result[$key] = $item->prependToEachKey($suffix); |
|
| 4201 | } elseif (\is_array($item) === true) { |
|
| 4202 | $result[$key] = self::create( |
|
| 4203 | $item, |
|
| 4204 | $this->iteratorClass, |
|
| 4205 | false |
|
| 4206 | )->prependToEachKey($suffix) |
|
| 4207 | ->toArray(); |
|
| 4208 | } else { |
|
| 4209 | $result[$key . $suffix] = $item; |
|
| 4210 | } |
|
| 4211 | } |
|
| 4212 | ||
| 4213 | return self::create( |
|
| 4214 | $result, |
|
| 4215 | $this->iteratorClass, |
|
| 4216 | false |
|
| 4217 | ); |
|
| 4218 | } |
|
| 4219 | ||
| 4220 | /** |
|
| 4221 | * Add a suffix to each value. |
|