DOes it make sense to use Arrow FX and Flow from c...
# arrow
j
DOes it make sense to use Arrow FX and Flow from coroutines?
s
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
suspend
. For example, Arrow Fx has support for
Schedule
and
Flow
for retrying. https://arrow-kt.io/docs/apidocs/arrow-fx-coroutines/arrow.fx.coroutines/kotlinx.coroutines.flow.-flow/retry.html
👍 2
j
Given that with flow it is possible to represent errors, what will be the purpose of using either ?
s
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) }
146 Views