Skip to content

Instantly share code, notes, and snippets.

@emiaj
Created January 29, 2014 21:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emiaj/8697991 to your computer and use it in GitHub Desktop.
Save emiaj/8697991 to your computer and use it in GitHub Desktop.
case class Car(Brand:String)
val tuple = ("this","is","a","tuple", 19, Car("Ford"))
// iterating over all items
tuple.productIterator.foreach(println)
/*
this
is
a
tuple
19
Car(Ford)
*/
tuple.productIterator.foreach({
case x:String => println("string " + x)
case x:Int => println("int " + x);
case x:Car => println("car " + x.Brand)
});
/*
string this
string is
string a
string tuple
int 19
car Ford
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment