I'm finding myself writing a lot of (sort of) boilerplate code. For example say I have the following traits
trait Foo {
def x: Int
}
trait Bar {
def y: Boolean
def z: String
}
Then I want a case class that does no more or less than implement these.
case class MyClass(x: Int, y: Boolean, z: String) extends Foo with Bar
This doesn't seem annoying, but now imagine that my traits have a dozen def
s each and that the names x
, y
, and z
are much longer. Writing the case class out means I have to rewrite all of these as arguments of MyClass
.
Is there a way to generate the x: Int, y: Boolean, z: String
constructor part automatically based on the traits I extend?