Join the elements of the array. Args: sep: The separator between elements. Returns: The joined elements.
(self, sep: StringVar | str = "")
| 63 | """Base class for immutable array vars.""" |
| 64 | |
| 65 | def join(self, sep: StringVar | str = "") -> StringVar: |
| 66 | """Join the elements of the array. |
| 67 | |
| 68 | Args: |
| 69 | sep: The separator between elements. |
| 70 | |
| 71 | Returns: |
| 72 | The joined elements. |
| 73 | """ |
| 74 | if not isinstance(sep, (StringVar, str)): |
| 75 | raise_unsupported_operand_types("join", (type(self), type(sep))) |
| 76 | if ( |
| 77 | isinstance(self, LiteralArrayVar) |
| 78 | and ( |
| 79 | len( |
| 80 | args := [ |
| 81 | x |
| 82 | for x in self._var_value |
| 83 | if isinstance(x, (LiteralStringVar, str)) |
| 84 | ] |
| 85 | ) |
| 86 | == len(self._var_value) |
| 87 | ) |
| 88 | and isinstance(sep, (LiteralStringVar, str)) |
| 89 | ): |
| 90 | sep_str = sep._var_value if isinstance(sep, LiteralStringVar) else sep |
| 91 | return LiteralStringVar.create( |
| 92 | sep_str.join( |
| 93 | i._var_value if isinstance(i, LiteralStringVar) else i for i in args |
| 94 | ) |
| 95 | ) |
| 96 | return array_join_operation(self, sep) |
| 97 | |
| 98 | def reverse(self) -> ArrayVar[ARRAY_VAR_TYPE]: |
| 99 | """Reverse the array. |