Accepted answer


val originalA: A = // ...
val update: Update = // ...
val newA: A = A(
  id =,
  a = update.a.getOrElse(originalA.a),


All case classes have a copy method. (find the copy term)

val a = A(1, "", "", "")
val update = Update(None, "scalaz".some, None)
val b = a.copy(
  b = update.b.getOrElse(a.b)

Also check out the lens pattern for copying deeply nested objects in a functional manner:

Once you have objects made up of other objects and so on, it becomes highly cumbersome to use the copy method. Scalaz's lens pattern implementation is a great alternative.

Related Query

More Query from same tag