【发布时间】:2018-11-14 21:16:05
【问题描述】:
我是 shapeless 的新手(在 scala 的学习曲线中仍然处于低水平...),我很难使用 shapeless
import shapeless._
case class FooBar[T](foo: String, bar: T)
val hl = 0 :: FooBar("A", "one") :: FooBar("B", 1) :: "0" :: FooBar("C", "two") :: HNil
val l = hl.filter[FooBar[String]].toList
println(l) //List(FooBar(A,one), FooBar(C,two))
效果很好
下一步,我想把它放在函数中,比如
def filter[T](hl: HList): List[FooBar[T]] = ???
所以我可以简化调用
filter[String](hl)
filter[Int](hl)
我天真地测试过
def filter[T](hl: HList): List[FooBar[T]] = {
hl.filter[FooBar[T]].toList
}
给了
could not find implicit value for parameter partition: shapeless.ops.hlist.Partition[shapeless.HList,FooBar[T]]
在尝试了一些隐式之后,我仍然没有找到正确的方法
你有什么想法吗?
谢谢!
【问题讨论】:
标签: scala implicit shapeless hlist