I need to abstract the copy method generated by Scala compiler for case classes with its parameters. In my case, I have a save method like below
def save[T<:Data](data:T):T={
// store in db and get the id
val dbId = ...
data.copy(dbId)
}
and a set of case classes like below
trait Data
case class Foo (id:Option[Int] = None,name:String,age:Int) extends Data
case class Bar (id:Option[Int] = None, name:String,address:String) extends Data
How can I abstract the copy method, any alternative solution would be appreciated.