Hello I am new in shapeless, I want to create Hlist from case class, than to modify fields than to create case class again, its possible by shapeless:
val user:RfModelCalibration = users.head
val transformer = Generic[RfModelCalibration]
val beforeTransform = transformer.to(user)
val afterTransform = beforeTransform.map(enumTransform)
val newCaseClass = transformer.from(afterTransform)
But I can't exec "beforeTransform.map(enumTransform)" Can I do It by shapeless?
Yes, you can.
The following code should compile:
import shapeless.{Generic, Poly1}
case class RfModelCalibration(field1: Field1, field2: Field2)
val user: RfModelCalibration = users.head
val transformer = Generic[RfModelCalibration]
val beforeTransform = transformer.to(user)
val afterTransform = beforeTransform.map(enumTransform)
val newCaseClass = transformer.from(afterTransform)
object enumTransform extends Poly1 {
implicit val cse1: Case.Aux[Field1, Field1] = at(x => ???)
implicit val cse2: Case.Aux[Field2, Field2] = at(x => ???)
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.