Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.