| @@ 985-1003 (lines=19) @@ | ||
| 982 | * @psalm-return static<TKey,T> |
|
| 983 | * @psalm-mutation-free |
|
| 984 | */ |
|
| 985 | public function appendToEachValue($prefix): self |
|
| 986 | { |
|
| 987 | // init |
|
| 988 | $result = []; |
|
| 989 | ||
| 990 | foreach ($this->getGenerator() as $key => $item) { |
|
| 991 | if ($item instanceof self) { |
|
| 992 | $result[$key] = $item->appendToEachValue($prefix); |
|
| 993 | } elseif (\is_array($item) === true) { |
|
| 994 | $result[$key] = self::create($item, $this->iteratorClass, false)->appendToEachValue($prefix)->toArray(); |
|
| 995 | } elseif (\is_object($item) === true) { |
|
| 996 | $result[$key] = $item; |
|
| 997 | } else { |
|
| 998 | $result[$key] = $prefix . $item; |
|
| 999 | } |
|
| 1000 | } |
|
| 1001 | ||
| 1002 | return self::create($result, $this->iteratorClass, false); |
|
| 1003 | } |
|
| 1004 | ||
| 1005 | /** |
|
| 1006 | * Sort an array in reverse order and maintain index association. |
|
| @@ 4115-4142 (lines=28) @@ | ||
| 4112 | * @psalm-return static<TKey,T> |
|
| 4113 | * @psalm-mutation-free |
|
| 4114 | */ |
|
| 4115 | public function prependToEachValue($suffix): self |
|
| 4116 | { |
|
| 4117 | // init |
|
| 4118 | $result = []; |
|
| 4119 | ||
| 4120 | foreach ($this->getGenerator() as $key => $item) { |
|
| 4121 | if ($item instanceof self) { |
|
| 4122 | $result[$key] = $item->prependToEachValue($suffix); |
|
| 4123 | } elseif (\is_array($item) === true) { |
|
| 4124 | $result[$key] = self::create( |
|
| 4125 | $item, |
|
| 4126 | $this->iteratorClass, |
|
| 4127 | false |
|
| 4128 | )->prependToEachValue($suffix) |
|
| 4129 | ->toArray(); |
|
| 4130 | } elseif (\is_object($item) === true) { |
|
| 4131 | $result[$key] = $item; |
|
| 4132 | } else { |
|
| 4133 | $result[$key] = $item . $suffix; |
|
| 4134 | } |
|
| 4135 | } |
|
| 4136 | ||
| 4137 | return self::create( |
|
| 4138 | $result, |
|
| 4139 | $this->iteratorClass, |
|
| 4140 | false |
|
| 4141 | ); |
|
| 4142 | } |
|
| 4143 | ||
| 4144 | /** |
|
| 4145 | * Return the value of a given key and |
|