Skip to content

Instantly share code, notes, and snippets.

@diegopacheco
Created January 7, 2012 21:58
Show Gist options
  • Select an option

  • Save diegopacheco/1576187 to your computer and use it in GitHub Desktop.

Select an option

Save diegopacheco/1576187 to your computer and use it in GitHub Desktop.
Scala Pattern Matcher Tuples
object MatcherOnTuples extends App {
def pointRef(i:Any) = i match {
case (x,y, 55) => printf("x y and 55")
case (x,y) => printf("Point X %s Y %s \n",x,y)
case (3) => printf("This is 3")
case (x) => printf("Point X %s \n",x)
}
pointRef( (1,2) )
pointRef( (3) )
pointRef( false )
pointRef( (3,Int) )
pointRef( (1,"1",55) )
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment