When I'm designing immutable objects, case classes are incredibly handy because of the auto-generated copy method.

But case classes have their own problems: they shouldn't be inherited from and they give you an extractor even if you don't want one.

So sometimes I have to use a garden-variety Scala class. The problem is that then I have to write my own immutable API, which can be pretty repetitive:

class Debt(principalBalance: Double, name: String, endDate: LocalDate) {
  def withNewPrincipalBalance(bal: Double) = new Debt(bal, name, endDate)
}

Is there a more scalable way to do this? Is there a compiler plugin I can use?

Edit
Report