Scala:迭代包含列表的元组列表的未来。需要 Future of tuple 的最终结果

Scala: Iterating over a Future of list of tuples containing lists as well. Need a final result of Future of tuple

我有一个假设

val a: Future[List[(List[Case_Class], List[Case_Class])]] = //some method call

在我的元组中,有两个列表,比如

listA = List[Case_Class] and listB = List[Case_Class]. 

两个列表一次都有两个元素。我需要的是将一些逻辑(例如:折叠)应用到我的 val 'a' 以实现

Future[(List(Case_Class), List(Case_Class))]

我必须应用的逻辑应该是什么?

类似

a.map(_.unzip match { case (x, y) => (x.flatten, y.flatten) })

请原谅下面示例中的括号数量不守规矩,但这似乎可行:

case class Thing()

val a: Future[List[(List[Thing], List[Thing])]] = {
  Future.successful(List((List(Thing()), List(Thing()))))
}

val b: Future[(List[Thing], List[Thing])] = {
  a.map(x => (x.unzip._1.flatten, x.unzip._2.flatten))
}

Await.ready(b, Duration.Inf)
// scala.concurrent.Future[(List[Thing], List[Thing])] =
// Future(Success((List(Thing()),List(Thing()))))

更多关于 unzip here