In Gleam it is possible to pattern match on the prefix of a string, making it very easy to pop off a known prefix and work with the remaining string:
case string {
"at://" <> hostname -> todo
_ -> todo
}
However it is not possible currently for the right hand side of <> to itself be a string pattern. In isolation this doesn't seem like a problem but when using OR patterns | it makes the following not possible to express:
case string {
"at://" <> "wibble" as wibble | "wibble" as wibble -> todo
_ -> todo
}
Here I want to match two exact strings - "at://wibble" or "wibble" - and extract the "wibble" portion for further use. It would be great if this were made possible as currently in the niche scenarios where this would be useful it leads to code duplication in branches or less clear code that involves manually popping the prefix.
In Gleam it is possible to pattern match on the prefix of a string, making it very easy to pop off a known prefix and work with the remaining string:
However it is not possible currently for the right hand side of
<>to itself be a string pattern. In isolation this doesn't seem like a problem but when using OR patterns|it makes the following not possible to express:Here I want to match two exact strings -
"at://wibble"or"wibble"- and extract the"wibble"portion for further use. It would be great if this were made possible as currently in the niche scenarios where this would be useful it leads to code duplication in branches or less clear code that involves manually popping the prefix.