title: Case classes - Copy multiple fields with transforms
body: <p>I have a case class with 25 fields and need to convert it into another with 22, of which 19 of these are shared and 3 are simply renamed. </p>
  
  <p>I have found a few examples of how to do this using <code>shapeless</code> (e.g. <a href="https://stackoverflow.com/questions/27634497/in-scala-how-to-convert-one-case-class-to-another-immune-to-code-changes-field-a">an answer here</a> and some code examples from Miles Sabin <a href="https://github.com/milessabin/shapeless/blob/master/examples/src/main/scala/shapeless/examples/labelledgeneric.scala" rel="nofollow noreferrer">here</a> and <a href="https://stackoverflow.com/questions/23192760/safely-copying-fields-between-case-classes-of-different-types">here</a>) but the last of those looks a bit out of date, and I can't figure out from the Github example how I can use shapeless to rename multiple fields, or do more manipulation on a field before adding it to the new object. Can anyone help me out?</p>
  
  <p>Simplified code example;</p>
  
  <pre><code>import shapeless.LabelledGeneric
  case class A(fieldA:Int, fieldB:String, fieldC:String)
  case class B(fieldARenamed:Int, fieldB:String, fieldC:String, fieldCTransformed:String)
  
  val aGen = LabelledGeneric[A]
  val bGen = LabelledGeneric[B]
  
  val freddie = new A(1,"Freddie","somestring")
  
  val record = aGen.to(freddie)
  val atmp = freddie.fieldA
  record.Remove("fielda")
  
  val freddieB = bGen.from(record + 
    (Symbol("fieldARenamed") -&gt;&gt; atmp) +
    (Symbol("fieldCTransformed") -&gt;&gt; freddie.fieldC.toUpperCase)
  ) //Errors everywhere, even if I replace + with :: etc.
  </code></pre>
  
  <p>I have a feeling <code>Align</code> is going to come into the picture somewhere here, but understanding how to do this in the leanest possible fashion - e.g. without creating additional traits like <code>Field</code>, as in that third link above - would be interesting.</p>
  
  <p>In <a href="https://books.underscore.io/shapeless-guide/shapeless-guide.html" rel="nofollow noreferrer">The Shapeless Guide</a>, there is also some usage of a single quote, (e.g. <code>'fieldC</code>) notation, which I haven't been able to find much information on, so if that plays a role some explanation would also be really helpful. Fairly new to this depth of Scala sorcery, so apologies if the question seems obtuse or covers too many disparate topics.</p>
  
  <p>EDIT: For the avoidance of doubt, I <strong>am not</strong> looking for answers which suggest that I just manually create a new case class by referencing fields from the first, as in;</p>
  
  <pre><code>val freddieB = B(fieldARenamed = freddie.fieldA, fieldB = freddie.fieldB, fieldC = freddie.fieldC, fieldCTransformed =freddie.fieldC.toUpperCase)
  </code></pre>
  
  <p>See below comment for various reasons why this is inappropriate.</p>