DOes it make sense to use Arrow FX and Flow from coroutines?
s
simon.vergauwen
05/11/2021, 8:07 AM
Absolutely. Arrow Fx is build on top of KotlinX Coroutines, and it relies on Flow as a streaming data type.
We hope to add extend the functionality of Flow further like we did for
Given that with flow it is possible to represent errors, what will be the purpose of using either ?
s
simon.vergauwen
05/11/2021, 5:54 PM
It's only possible with
Flow
to represent errors in the
Throwable
domain. Just like
suspend
.
It doesn't offer any utilities to model errors in a typed manner, that is where
Either
comes in. It works the same whether you use
suspend
or
Flow
.
For example:
Copy code
/** Returns a single [User] for a given [Id] or [UserNotFound] if [User] doesn't exist for [Id] *//
suspend fun fetchUser(id: Id): Either<UserNotFound, User> = TODO()
fun flowUsers(ids: Flow<Int>): Flow<Either<UserNotFound, User>> = ids.map { id -> fetchUser(id) }