Created
March 19, 2015 23:14
-
-
Save fancellu/2395b8e614c48d096990 to your computer and use it in GitHub Desktop.
Case to tuple and back
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
case class Person(name:String,age:Int) | |
val dino=Person("dino",48) //> dino : stuff.Person = Person(dino,48) | |
// get tuple from case class, decompose | |
val (name,age)=Person.unapply(dino).get //> name : String = dino | |
//| age : Int = 48 | |
// create case class from composed tuple | |
val dino2=Person.tupled((name,age)) //> dino2 : stuff.Person = Person(dino,48) | |
dino==dino2 //> res10: Boolean = true | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://michalostruszka.pl/blog/2015/03/30/scala-case-classes-to-and-from-tuples/
Note complication with tupled if case class has a companion object