Created
November 25, 2010 11:53
-
-
Save fedesilva/715266 to your computer and use it in GitHub Desktop.
Record Features
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
// | |
// A class does not need any reference to the `Mapper`. | |
// Here it is defined as a case class because it's convenient - no need for new and | |
// the compiler generates equals, hashCode, copy and extractor methods - but | |
// it can be a normal class. | |
// | |
case class Person( first:String, last:String, age:Int ) | |
// | |
// A record does not need to be a class companion but it is convenient | |
// because the implicit conversion to `Record` is automatically in scope. | |
// ( see tests below ) | |
// | |
object Person extends Mapper[Person] { | |
def key = first | |
val first = "first" is { _.first } // name is getter | |
val last = "last" is { _.last } | |
val age = "age" is { _.age } | |
//Same order as the constructor | |
def properties = first :: last :: age :: Nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment