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