Created
July 26, 2011 08:06
-
-
Save kings13y/1106241 to your computer and use it in GitHub Desktop.
Partial updates with immutable domain objects
This file contains 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(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, "[email protected]") | |
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