Skip to content

Allow literal patterns on right-hand side of string prefix patterns. #5995

Description

@hayleigh-dot-dev

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions