I have many case classes in the format of
case class Cluster (id: Pk[Long],
foo: Long,
bar: String,
env: String,
name: String,
deleted: Boolean = false) {
def delete() = Cluster(id, foo, bar, env, name, true)
def updateName(name: String) = Cluster(id, foo, bar, env, name, deleted)
def updateFoo(foo: Long) = Cluster(id, foo, bar, env, name, deleted)
}
I and trying to have all of my classes immutable, i.e. update methods are creating a new instance.
Some of the classes have many more members and having the update methods cloning the self object with a different value is tedies error prone.
Any ideas of how to make it more efficient?
You don’t need your methods. You just need to:
The copy() method is available on case classes “for free”.