funcy icon indicating copy to clipboard operation
funcy copied to clipboard

Adding an optional guard condition

Open AdamBrodzinski opened this issue 9 years ago • 3 comments

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.

AdamBrodzinski avatar Oct 29 '15 17:10 AdamBrodzinski

+1

aleffsouza avatar May 31 '16 12:05 aleffsouza

+1

gabrielmancini avatar Sep 13 '16 14:09 gabrielmancini

any update on this @bramstein ? :)

gregory avatar Mar 13 '17 08:03 gregory