0
我預計代碼編譯無形:爲什麼align不適用於singleton類型?
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))
,但如果失敗,
could not find implicit value for parameter alm: shapeless.ops.hlist.Align[modified.type,toGen.Repr]
val align = Align[modified.type, toGen.Repr]
有a trick與構建使用labelled.FieldType
需要的類型,但它沒有解釋如何刪除字段,因此如果不可能使Align
與singleton類型一起工作,知道如何處理這些字段將是有用的。