1

I have IO[Throwable, Seq[IO[Nothing, String]]] and I would like to turn it into IO[Throwable, Seq[String]] . Any idea how ? I tried with flatten but I get weird implicit missing errors.

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

Thank you !

1 Answer 1

3

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

2
  • 2
    How about data1.flatMap(IO.sequence)? (not sure whether it compiles, didn't check whether it works out with all the variances) Dec 22, 2018 at 12:58
  • 1
    oh yeah that's what I did in my code, I was detailing step by step.
    – Wonay
    Dec 22, 2018 at 19:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.