Hi, I have such “nice” result: ```val results: List<IO<Either<ListenerError, Unit>>&g...
d
Hi, I have such “nice” result:
Copy code
val results: List<IO<Either<ListenerError, Unit>>> = ...
and want to convert it to
IO<Either<ListenerError, List<Unit>>>
This is what I got to achieve it:
Copy code
val r = results.sequence(IO.applicative()).fix().map { l ->
    l.fix().sequence(Either.applicative()).fix().map { list ->
        list.fix()
    }
}
Is there any better/nicer way?
s
Not really, you could work with
EitherT
.
Copy code
results.map { EitherT(it) }
       .sequence(EitherT.applicative(IO.applicative()))
.map { it.map { it.fix() } }
but doesn’t much nicer results due to
fix()
. disclaimer, wrote this from memory
d
Thank you for advice 🙂