Skip to content

Instantly share code, notes, and snippets.

@kings13y
Created July 26, 2011 08:06
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 kings13y/1106241 to your computer and use it in GitHub Desktop.
Save kings13y/1106241 to your computer and use it in GitHub Desktop.
Partial updates with immutable domain objects
case class Person(val firstName: String, val lastName: String, val age: Int, val email: String) {
def update(firstName: String = firstName, lastName: String = lastName, age: Int = age, email: String = email) : Person = {
Person(firstName, lastName, age, email)
}
}
val seedPerson = Person("A", "B", 1, "me@home.com")
println(seedPerson)
val updatedPerson = seedPerson update (age = 100, firstName = "Z")
println(updatedPerson)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment