title: How can I add a trait to a case class?
body: <p>I have a domain model that looks like this:</p>
  
  <pre><code>case class Account(id: Int, name: String)
  
  trait BalanceTotal {
    def balance: BigDecimal
  }
  </code></pre>
  
  <p>My goal is to have a simple, lightweight <code>Account</code> case class and then an enhanced class <code>Account with BalanceTotal</code> that will only be created inside a method that does the balance calculation (which is expensive).</p>
  
  <p>With this structure, I can statically ensure that I'm never counting on a balance being present when I just have a lightweight object. I know about <code>Option</code>, of course, but I want the type-checker to prevent code from using the lightweight object where I need the balance-enriched object, and vice-versa, and I don't think <code>Option</code> gives me that.</p>
  
  <p>Anyway, what I'd like to do is:</p>
  
  <pre><code>for{ Account(id,name) &lt;- accounts } {
    yield Account(id, name) with BalanceTotal {
      override val balance = BigDecimal(44)
    }
  }
  </code></pre>
  
  <p>but that fails with:</p>
  
  <pre><code>';' expected but 'with' found
  </code></pre>
  
  <p>If I try to use <code>new Account</code> instead of <code>Account</code>, I get:</p>
  
  <pre><code>super constructor arguments cannot reference unconstructed `this`
  </code></pre>
  
  <p>which I assume has something to do with the voodoo that makes case classes work.</p>
  
  <p>Is it possible to do what I'm trying to do?</p>
  
  <p><em>Update</em>: On further consideration, I guess this has something to do with the prohibition against case class inheritance. But I really do need case class magic here: I'm relying on the generated <code>apply</code> and <code>unapply</code> methods for my ScalaQuery mappings.</p>