Created
September 20, 2023 12:48
-
-
Save anderseknert/12668693b2a2f10874952c745479da75 to your computer and use it in GitHub Desktop.
Pattern matching
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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