假设我有一个hlist
val hlist: Boolean :: Int :: HNil = true :: 42 :: HNil
我有一个模式
type Pattern = Int :: Boolean :: HNil
如何使用模式重新排序现有的hlist?即。
reorder[Int :: Boolean :: HNil](hlist) // 42 :: true :: HNil
答案 0 :(得分:4)
您正在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