Sourabh Rawat
12/15/2021, 3:44 PMFlow of Either ? I want to do a fold on it as a terminal operator.simon.vergauwen
12/15/2021, 5:06 PMFlow if you encounter Either.Left?
Otherwise you could write:
suspend fun <E, A> Flow<Either<E, A>>.fold(left: suspend (E) -> Unit, right: suspend (A) -> Unit) : Unit =
collect { either ->
either.fold({ left(it) }, { right(it) })
}Sourabh Rawat
12/16/2021, 4:32 AMeither {
lst.asFlow()
.map { callServiceReturningEither(it) }
.fold(initAcc) { acc, eitherRes -> acc.combine(eitherRes.bind()) }
}
I am not sure if this will short circuit properly.simon.vergauwen
12/16/2021, 9:17 AMEither.Left.bind() inside fold it will short-circuit the `fold`/`Flow#collect` and it’ll return the encountered Either.Left.