Skip to content

Adding an optional guard condition #6

@AdamBrodzinski

Description

@AdamBrodzinski

I was wondering what you thought about potentially adding guard statements as an optional parameter? It basically would have to match the pattern plus the expression would have to be equal true for the match to execute.

For example Elixir has a pattern match and an optional guard:

def serve_drinks({age: age}) when age >= 21 do
  # Code that serves drinks!
end

serve_drinks User.get("John Doe")
#=> Fails if the user is under 21

I've been tinkering with an experimental compile-to-js functional language that uses pattern matching and will be using this lib in my proof of concept compiler (also not prod ready). https://github.com/AdamBrodzinski/RedScript#pattern-matching-coming-soon

I would love to contribute back if guard conditions are something you'd like to add.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions