I've been using Arrow-KT for a long time now. I'm much newer to coroutines and the programming model around them, this is my first project using them. I've got the following scenario:
Either.catch { funcThatReturnsFlow() }
.map { flow ->
flow.map { flowItem -> mappingFuncThatReturnsEither(flowItem) }
}
// Type is now Either<Throwable, Flow<Either<Throwable, Item>>>
As you can see from the above example, I'm working with a Flow for the first time. I want to handle exceptions from the function that returns a Flow, so I wrap it in Either.catch
. Then I want to map over each item in the flow with a function that also returns an Either
. As a result I now have an output of Either<Throwable, Flow<Either<Throwable, Item>>>
.
I could collapse this using the following code:
resultFromBefore.flatMap { flow -> flow.toList().sequence() }
// Type is now Either<Throwable, List<Item>>
The problem with that is it puts the Flow
through a collection process to produce a normal List
. The dataset I'm working with is quite small so it's trivial to do this, but one of my goals is to get better with coroutines.
So, I'm wondering if there is any equivalent form of sequence()
for the Flow type? Something that would transform Either<Throwable, Flow<Either<Throwable, Item>>>
into Either<Throwable, Flow<Item>>
.