Scala用Future转换Seq [英] Scala transforming a Seq with Future

查看:108
本文介绍了Scala用Future转换Seq的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像这样的元组Seq:

I have a Seq of a tuple that looks like this:

Seq[(Future[Iterable[Type1]], Future[Iterator[Type2]])]

我想将其转换为以下内容:

I want to transform this into the following:

Future[Seq([Iterable[Type1], [Iterable[Type2])]

这有可能吗?

推荐答案

这应该可以解决问题

val a: Seq[(Future[Iterable[Type1]], Future[Iterable[Type2]])] = ...

val b: Future[Seq[(Iterable[Type1], Iterable[Type2])]] = Future.sequence(a.map{
  case (l, r) => l.flatMap(vl => r.map(vr => (vl, vr)))
})

这篇关于Scala用Future转换Seq的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆