简体   繁体   English

scalaz.io:扁平化IO [Throwable,Seq [IO [Nothing,String]]]

[英]scalaz.io : flatten IO[Throwable, Seq[IO[Nothing, String]]]

I have IO[Throwable, Seq[IO[Nothing, String]]] and I would like to turn it into IO[Throwable, Seq[String]] . 我有IO[Throwable, Seq[IO[Nothing, String]]] ,我想把它变成IO[Throwable, Seq[String]] Any idea how ? 任何想法如何? I tried with flatten but I get weird implicit missing errors. 我尝试使用flatten但出现了奇怪的隐式丢失错误。

No implicits found for parameter asTraversable: IO[Nothing, Step] => GenTraversableOnce[B_]

Thank you ! 谢谢 !

I found the solution: 我找到了解决方案:

val data1: IO[Throwable, Seq[IO[Nothing, String]]]
val data2: IO[Throwable, IO[Nothing, Seq[String]]] = data1.map(IO.sequence)
val data3: IO[Throwable, Seq[String]] = data2.flatten

To do it in one step: 要一步完成:

data1.flatMap(IO.sequence)

Courtesy of @andrey-tyukin @ andrey-tyukin提供

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM