title: Mixing in a trait dynamically
body: <p>Having a trait</p>
  
  <pre><code>trait Persisted {
    def id: Long
  }
  </code></pre>
  
  <p>how do I implement a method that accepts an instance of any case class and returns its copy with the trait mixed in?</p>
  
  <p>The signature of the method looks like:</p>
  
  <pre><code>def toPersisted[T](instance: T, id: Long): T with Persisted
  </code></pre>