Skip to content

Instantly share code, notes, and snippets.

@fedesilva
Created November 25, 2010 11:53
Show Gist options
  • Save fedesilva/715266 to your computer and use it in GitHub Desktop.
Save fedesilva/715266 to your computer and use it in GitHub Desktop.
Record Features
//
// 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