Skip to content

Instantly share code, notes, and snippets.

@anderseknert
Created September 20, 2023 12:48
Show Gist options
  • Save anderseknert/12668693b2a2f10874952c745479da75 to your computer and use it in GitHub Desktop.
Save anderseknert/12668693b2a2f10874952c745479da75 to your computer and use it in GitHub Desktop.
Pattern matching
# First name may be either "joe" or "jane" for function to evaluate
# No rule body needed as argument passed will be matched for equality
allowed_firstname("joe")
allowed_firstname("jane")
# This works with multiple arguments too, where only some are matched
# statically
alcohol_allowed("Sweden", age) if age > 18
alcohol_allowed("USA", age) if age > 21
alcohol_allowed(country, age) if {
# for any other country, we'll need to look up the rules for the country
# provided, perhaps by using http.send
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment