Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create common trait for all case classes supporting copy(id=newId) method

I'm trying to do something like that:

trait IdentifiableModel[T] {
  self: { def copy(id: ObjectId): T } =>

  val id: ObjectId
}

I've found some other related questions trying to do similar things but they didn't really answer to this question. In my case, I'm trying to copy the case class subclasses of IdentifiableModel that all share an id value

like image 390
Sebastien Lorber Avatar asked Feb 25 '13 22:02

Sebastien Lorber


1 Answers

Travis Brown has the good answer but didn't reply.

He uses Scala macros: Howto model named parameters in method invocations with Scala macros?

like image 182
Sebastien Lorber Avatar answered Sep 19 '22 13:09

Sebastien Lorber