| @@ 970-988 (lines=19) @@ | ||
| 967 | * @psalm-return static<TKey,T> |
|
| 968 | * @psalm-mutation-free |
|
| 969 | */ |
|
| 970 | public function appendToEachValue($prefix): self |
|
| 971 | { |
|
| 972 | // init |
|
| 973 | $result = []; |
|
| 974 | ||
| 975 | foreach ($this->getGenerator() as $key => $item) { |
|
| 976 | if ($item instanceof self) { |
|
| 977 | $result[$key] = $item->appendToEachValue($prefix); |
|
| 978 | } elseif (\is_array($item) === true) { |
|
| 979 | $result[$key] = self::create($item, $this->iteratorClass, false)->appendToEachValue($prefix)->toArray(); |
|
| 980 | } elseif (\is_object($item) === true) { |
|
| 981 | $result[$key] = $item; |
|
| 982 | } else { |
|
| 983 | $result[$key] = $prefix . $item; |
|
| 984 | } |
|
| 985 | } |
|
| 986 | ||
| 987 | return self::create($result, $this->iteratorClass, false); |
|
| 988 | } |
|
| 989 | ||
| 990 | /** |
|
| 991 | * Sort an array in reverse order and maintain index association. |
|
| @@ 4016-4043 (lines=28) @@ | ||
| 4013 | * @psalm-return static<TKey,T> |
|
| 4014 | * @psalm-mutation-free |
|
| 4015 | */ |
|
| 4016 | public function prependToEachValue($suffix): self |
|
| 4017 | { |
|
| 4018 | // init |
|
| 4019 | $result = []; |
|
| 4020 | ||
| 4021 | foreach ($this->getGenerator() as $key => $item) { |
|
| 4022 | if ($item instanceof self) { |
|
| 4023 | $result[$key] = $item->prependToEachValue($suffix); |
|
| 4024 | } elseif (\is_array($item) === true) { |
|
| 4025 | $result[$key] = self::create( |
|
| 4026 | $item, |
|
| 4027 | $this->iteratorClass, |
|
| 4028 | false |
|
| 4029 | )->prependToEachValue($suffix) |
|
| 4030 | ->toArray(); |
|
| 4031 | } elseif (\is_object($item) === true) { |
|
| 4032 | $result[$key] = $item; |
|
| 4033 | } else { |
|
| 4034 | $result[$key] = $item . $suffix; |
|
| 4035 | } |
|
| 4036 | } |
|
| 4037 | ||
| 4038 | return self::create( |
|
| 4039 | $result, |
|
| 4040 | $this->iteratorClass, |
|
| 4041 | false |
|
| 4042 | ); |
|
| 4043 | } |
|
| 4044 | ||
| 4045 | /** |
|
| 4046 | * Return the value of a given key and |
|