given:
sealed trait Data
final case class Foo() extends Data
final case class Bar() extends Data
final case class TimestampedData[A <: Data](data: A, timestamp: Long)
Is there a succint way to generate, for example, a Generic.Aux that will take a
(A, Long) where A <: Data
and out this Coproduct:
TimestampedData[Foo] :+: TimestampedData[Bar] :+: CNil
(Generic.Aux[(A, Long), TimestampedData[Foo] :+: TimestampedData[Bar] :+: CNil])
?
Unfortunately, since I don't know much generic programming and because of the lack of resources, I haven't tried much. I'm not even sure how to approach this problem.
Thanks
You can try a method with
PartiallyAppliedpatternor a typeclass 1 2 3 4 5 (generally, a more flexible solution than a method although now there seem to be no advantages over a method because there is the only instance of the type class)
Testing:
In Shapeless there is
MappedforHListbut notCoproduct, so I had to transform on type levelCoproducttoHListand back.λ[A => ...]is kind-projector syntax.Mappedaccepts a type constructorF[_]butTimestampedDatais upper-boundedF[_ <: Data], so I had to use a type lambda with intersection type (with).