Lets say I have the following:
case class TestField(value: String)
case class TestField2(value: String)
implicit class ProductExtensions[T <: Product](val va
Here is generalized version
implicit class ProductExtensions[T <: Product, L <: HList](val value: T) extends AnyVal {
def mapTo[R <: Product](implicit tGen: Generic.Aux[T, L], rGen: Generic.Aux[R, L]): R = rGen.from(tGen.to(value))
}
The Type Astronaut’s Guide to Shapeless. 6.3 Case study: case class migrations https://books.underscore.io/shapeless-guide/shapeless-guide.html#sec:ops:migration
New version
import shapeless.ops.hlist.IsHCons
implicit class ProductExtensions[T <: Product, L <: HList, U, L1 <: HList](val value: T) extends AnyVal {
def mapTo[R <: Product](implicit
tGen: Generic.Aux[T, L],
rGen: Generic.Aux[R, L],
isHCons: IsHCons.Aux[L, U, L1],
o: OtherImplicit[U]
): R = rGen.from(tGen.to(value))
}
4.3 Chaining dependent functions https://books.underscore.io/shapeless-guide/shapeless-guide.html#sec:type-level-programming:chaining
Scala shapeless Generic.Aux implicit parameter not found in unapply