| @@ 790-808 (lines=19) @@ | ||
| 787 | * @psalm-return static<TKey,T> |
|
| 788 | * @psalm-mutation-free |
|
| 789 | */ |
|
| 790 | public function appendToEachValue($prefix): self |
|
| 791 | { |
|
| 792 | // init |
|
| 793 | $result = []; |
|
| 794 | ||
| 795 | foreach ($this->getGenerator() as $key => $item) { |
|
| 796 | if ($item instanceof self) { |
|
| 797 | $result[$key] = $item->appendToEachValue($prefix); |
|
| 798 | } elseif (\is_array($item) === true) { |
|
| 799 | $result[$key] = self::create($item, $this->iteratorClass, false)->appendToEachValue($prefix)->toArray(); |
|
| 800 | } elseif (\is_object($item) === true) { |
|
| 801 | $result[$key] = $item; |
|
| 802 | } else { |
|
| 803 | $result[$key] = $prefix . $item; |
|
| 804 | } |
|
| 805 | } |
|
| 806 | ||
| 807 | return self::create($result, $this->iteratorClass, false); |
|
| 808 | } |
|
| 809 | ||
| 810 | /** |
|
| 811 | * Sort an array in reverse order and maintain index association. |
|
| @@ 3672-3699 (lines=28) @@ | ||
| 3669 | * @psalm-return static<TKey,T> |
|
| 3670 | * @psalm-mutation-free |
|
| 3671 | */ |
|
| 3672 | public function prependToEachValue($suffix): self |
|
| 3673 | { |
|
| 3674 | // init |
|
| 3675 | $result = []; |
|
| 3676 | ||
| 3677 | foreach ($this->getGenerator() as $key => $item) { |
|
| 3678 | if ($item instanceof self) { |
|
| 3679 | $result[$key] = $item->prependToEachValue($suffix); |
|
| 3680 | } elseif (\is_array($item) === true) { |
|
| 3681 | $result[$key] = self::create( |
|
| 3682 | $item, |
|
| 3683 | $this->iteratorClass, |
|
| 3684 | false |
|
| 3685 | )->prependToEachValue($suffix) |
|
| 3686 | ->toArray(); |
|
| 3687 | } elseif (\is_object($item) === true) { |
|
| 3688 | $result[$key] = $item; |
|
| 3689 | } else { |
|
| 3690 | $result[$key] = $item . $suffix; |
|
| 3691 | } |
|
| 3692 | } |
|
| 3693 | ||
| 3694 | return self::create( |
|
| 3695 | $result, |
|
| 3696 | $this->iteratorClass, |
|
| 3697 | false |
|
| 3698 | ); |
|
| 3699 | } |
|
| 3700 | ||
| 3701 | /** |
|
| 3702 | * Return the value of a given key and |
|