Skip to content

Commit

Permalink
simplify join with all literal string vars
Browse files Browse the repository at this point in the history
  • Loading branch information
adhami3310 committed Sep 24, 2024
1 parent 75ea758 commit b4819d9
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions reflex/vars/sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,26 @@ def join(self, sep: Any = "") -> StringVar:
"""
if not isinstance(sep, (StringVar, str)):
raise_unsupported_operand_types("join", (type(self), type(sep)))
if (
isinstance(self, LiteralArrayVar)
and (
len(
args := [
x
for x in self._var_value
if isinstance(x, (LiteralStringVar, str))
]
)
== len(self._var_value)
)
and isinstance(sep, (LiteralStringVar, str))
):
sep_str = sep._var_value if isinstance(sep, LiteralStringVar) else sep
return LiteralStringVar.create(
sep_str.join(
i._var_value if isinstance(i, LiteralStringVar) else i for i in args
)
)
return array_join_operation(self, sep)

def reverse(self) -> ArrayVar[ARRAY_VAR_TYPE]:
Expand Down

0 comments on commit b4819d9

Please sign in to comment.