Created
March 22, 2011 23:39
-
-
Save kings13y/882344 to your computer and use it in GitHub Desktop.
Simple Tuple pattern match
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
val doubleA1 = ("A", 1) | |
val doubleA2 = ("A", 2) | |
val doubleB1 = ("B", 3) | |
def tupleMatcher(tuple: Tuple2[String, Int]) = tuple match { | |
case (_,1) => "matched A1 !" | |
case (_,2) => "matched A2 !" | |
case (a,b) if(a == "B") => "matched and using a guard for B !" | |
} | |
tupleMatcher(doubleA2) | |
tupleMatcher(doubleB1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment