【发布时间】:2017-07-31 09:28:13
【问题描述】:
我想将列表和期货混合在一起以供理解
val list: List[Int] = List(1,2,3)
def f1(i: Int): Future[Boolean] = ???
def f2(i: Int): Future[List[Int]] = ???
看着this answer 如果我用 future 包装列表并将 f 返回类型转换为 List
,这很好用import scalaz._
import ListT._
val x: Future[List[Boolean]] = (for {
i <- listT(Future{ls})
c <- listT(f2(i))
b <- listT(f1(c).map(List(_)))
} yield b).run
我正在寻找的输出应该是Future[List[Boolean]]
但是,使用 Future 对列表进行所有这些包装并将布尔值转换为列表似乎效率低下。我不得不使用另一个库(scalaz)
有什么简化的建议吗?
【问题讨论】: