funcy
funcy copied to clipboard
Adding an optional guard condition
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.
+1
+1
any update on this @bramstein ? :)