【发布时间】:2011-03-06 03:13:59
【问题描述】:
如果我想将以下方法推广到支持所有必要操作的所有集合类型(foldLeft、flatMap、map 和 :+),那么我该怎么做?目前它只适用于列表。
代码:
def join[A](lists: List[List[A]]): List[List[A]] = {
lists.foldLeft(List(List[A]())) { case (acc, cur) =>
for {
a <- acc
c <- cur
} yield a :+ c
}
}
【问题讨论】:
标签: scala collections higher-kinded-types