Skip to content

Instantly share code, notes, and snippets.

@kings13y
Created March 22, 2011 23:39
Show Gist options
  • Save kings13y/882344 to your computer and use it in GitHub Desktop.
Save kings13y/882344 to your computer and use it in GitHub Desktop.
Simple Tuple pattern match
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