-
-
Save simi/39edef987a19c0471032ea57e68c5589 to your computer and use it in GitHub Desktop.
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
# case version | |
case expr | |
in pat [if|unless cond] | |
... | |
in pat [if|unless cond] | |
... | |
else | |
... | |
end | |
pat: var # Variable pattern. It matches any value, and binds the variable name to that value. | |
| literal # Value pattern. The pattern matches an object such that pattern === object. | |
| Constant # Ditto. | |
| var_ # Ditto. It is equivalent to pin operator in Elixir. | |
| (pat, ..., *var, pat, ..., id:, id: pat, ..., **var) # Deconstructing pattern. See below for more details. | |
| pat(pat, ...) # Ditto. Syntactic sugar of (pat, pat, ...). | |
| pat, ... # Ditto. You can omit the parenthesis (top-level only). | |
| pat | pat | ... # Alternative pattern. The pattern matches if any of pats match. | |
| pat => var # As pattern. Bind the variable to the value if pat match. | |
# one-liner version | |
$(pat, ...) = expr # Deconstructing pattern. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment