[英]Scala shapeless: how to convert a hlist.Mapper to a case class?
我是無形的新手,我想將Mapper[mix.type, HNil]#Out
轉換為案例類
我怎樣才能做到這一點? (讓我知道您是否需要更多信息...)
僅當您定義具有與此Mapper#Out
形狀完全相同的形狀的case類時,這才起作用。 如果是這樣,您可以使用shapeless.Generic
創建您的case類的實例:
val mout = ... // HList coming from your Mapper
case class A(i: Int, s: String)
shapeless.Generic[A].from(mout): A
假設Generic#Repr
和Mapper[mix.type, HNil]#Out
是相同的類型,可以使用以下命令進行檢查:
val mapper = the[Mapper[mix]]
val gen = the[Generic[A]]
implicitly[mapper#Out =:= gen#Repr] // This only complies if scalac can
// prove equality between these types
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.