| @@ 788-806 (lines=19) @@ | ||
| 785 | * |
|
| 786 | * @psalm-return static<TKey,T> |
|
| 787 | */ |
|
| 788 | public function appendToEachValue($prefix): self |
|
| 789 | { |
|
| 790 | // init |
|
| 791 | $result = []; |
|
| 792 | ||
| 793 | foreach ($this->getGenerator() as $key => $item) { |
|
| 794 | if ($item instanceof self) { |
|
| 795 | $result[$key] = $item->appendToEachValue($prefix); |
|
| 796 | } elseif (\is_array($item) === true) { |
|
| 797 | $result[$key] = self::create($item, $this->iteratorClass, false)->appendToEachValue($prefix)->toArray(); |
|
| 798 | } elseif (\is_object($item) === true) { |
|
| 799 | $result[$key] = $item; |
|
| 800 | } else { |
|
| 801 | $result[$key] = $prefix . $item; |
|
| 802 | } |
|
| 803 | } |
|
| 804 | ||
| 805 | return self::create($result, $this->iteratorClass, false); |
|
| 806 | } |
|
| 807 | ||
| 808 | /** |
|
| 809 | * Sort an array in reverse order and maintain index association. |
|
| @@ 3615-3642 (lines=28) @@ | ||
| 3612 | * |
|
| 3613 | * @psalm-return static<TKey,T> |
|
| 3614 | */ |
|
| 3615 | public function prependToEachValue($suffix): self |
|
| 3616 | { |
|
| 3617 | // init |
|
| 3618 | $result = []; |
|
| 3619 | ||
| 3620 | foreach ($this->getGenerator() as $key => $item) { |
|
| 3621 | if ($item instanceof self) { |
|
| 3622 | $result[$key] = $item->prependToEachValue($suffix); |
|
| 3623 | } elseif (\is_array($item) === true) { |
|
| 3624 | $result[$key] = self::create( |
|
| 3625 | $item, |
|
| 3626 | $this->iteratorClass, |
|
| 3627 | false |
|
| 3628 | )->prependToEachValue($suffix) |
|
| 3629 | ->toArray(); |
|
| 3630 | } elseif (\is_object($item) === true) { |
|
| 3631 | $result[$key] = $item; |
|
| 3632 | } else { |
|
| 3633 | $result[$key] = $item . $suffix; |
|
| 3634 | } |
|
| 3635 | } |
|
| 3636 | ||
| 3637 | return self::create( |
|
| 3638 | $result, |
|
| 3639 | $this->iteratorClass, |
|
| 3640 | false |
|
| 3641 | ); |
|
| 3642 | } |
|
| 3643 | ||
| 3644 | /** |
|
| 3645 | * Return the value of a given key and |
|