Last active
September 30, 2019 08:33
-
-
Save MaxwellBo/92567ce6f325057e5bf31ba45bff8a20 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
val Pattern = "([a-cA-C])".r | |
def matchExample(x: AnyVal): Unit = { | |
x match { | |
case i: Int => "Matching on type" | |
case 1 => "Matching on a literal" | |
case 2 | 3 => "Matching on multiple literals" | |
case x if 0 until 10 contains x => "Matching with guard" | |
case ab@(a, b) => "Matching and destructuring a tuple, but keeping the original tuple bound to ab" | |
case x::xs => "Matching and destructuring a list" | |
case Pattern(c) => "c bound to capture group here (if x were a string). This will fail if the Regex doesn't match" | |
case _ => "Matching wildcard" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment