Reputation: 320
I expected this code to compile
import shapeless._
import record._
import ops.record._
import ops.hlist.Align
import syntax.singleton._
case class From(i: Int, s: String, a: Int, b: Int, c: Int)
case class To(j: Int, s1: String, s2: String, a: Int, b: Int, c: Int)
val f = From(1, "FROM", 1, 1, 1)
val fromGen = LabelledGeneric[From]
val toGen = LabelledGeneric[To]
val lgenRepr = fromGen.to(f)
val modified = lgenRepr.renameField('i, 'j) - 's + ('s1 ->> "S1") + ('s2 ->> "S2")
val align = Align[modified.type, toGen.Repr]
toGen.from(align(modified))
but if fails with
could not find implicit value for parameter alm: shapeless.ops.hlist.Align[modified.type,toGen.Repr]
val align = Align[modified.type, toGen.Repr]
There is a trick with constructing the needed type using labelled.FieldType
, but it doesn't explain how to remove fields, so if it's impossible to make Align
work with singleton type, it would be useful to know how to deal with those fields.
Upvotes: 0
Views: 167
Reputation: 23046
The problem is that modified.type
is a little too precise ... it's the singleton type of that particular val, not the computed record type. To do this on the REPL the following works just fine,
@ modified.align[toGen.Repr]
res14: toGen.Repr = 1 :: S1 :: S2 :: 1 :: 1 :: 1 :: HNil
Upvotes: 2