【发布时间】:2013-05-23 21:59:00
【问题描述】:
我想做这样的事情:
def run(subjects: List[Subject]) = {
val configs = compute()
subjects.map(s => configs.map(c => test(s,c)))
// or flatMap, I don't really care at this point
}
在我的用例中,主题实际上是Subject[T],我需要在结果中使用T 的类型安全版本。所以我有:
def run[L <: HList](subjects: L)(implicit mapper: Mapper[testFun.type, L]) = {
val configs = compute()
subjects.map(testFun)
}
但是,现在我无法将配置传递给testFun,根据this post,它需要有一个单例类型。
一种选择是:
val cfgHL = HList.fill(subjects.length)(configs)
(subjects zip cfgHL).map(testFun)
但HList 目前没有fill 操作。有什么提示吗?
【问题讨论】:
-
HList 现在有一个填充方法(虽然还没有正式发布)。