假设我有一个 hlist
val hlist: Boolean :: Int :: HNil = true :: 42 :: HNil
我有一个模式
type Pattern = Int :: Boolean :: HNil
如何使用该模式重新排序现有的 hlist?IE
reorder[Int :: Boolean :: HNil](hlist) // 42 :: true :: HNil
您正在寻找align
和相应的Align
类型类shapeless.ops.hlist
,
scala> import shapeless._
import shapeless._
scala> val hlist: Boolean :: Int :: HNil = true :: 42 :: HNil
hlist: shapeless.::[Boolean,shapeless.::[Int,shapeless.HNil]] = true :: 42 :: HNil
scala> type Pattern = Int :: Boolean :: HNil
defined type alias Pattern
scala> hlist.align[Pattern]
res0: Pattern = 42 :: true :: HNil