I have been trying out arrow. I have an interestin...
# arrow
a
I have been trying out arrow. I have an interesting situation with modelling errors, its not specific to arrow library.. Lets say I have two modules,
account
and
savedroutes
. The
savedroutes
module depends on
account
module.
account
module has some failures
Copy code
interface Failure {
    val errorMessage: String
}
/**
 * Describes the domain failures related to user account
 */
sealed interface UserAccountInfoFailure : Failure {
    /** No user info, no token */
    data class UnAuthenticated(
        override val errorMessage: String
    ) : UserAccountInfoFailure
...
}
savedroutes
modules has some failures
Copy code
/**
 * Describes the domain failures related to saving a route.
 */
sealed interface SaveRouteFailure : Failure {
    data class RouteTooLongFailure(
        override val errorMessage: String
    ) : SaveRouteFailure
   ...
}
I have a method in
savedroutes
which returns
Copy code
fun getSavedRoutes(): Flow<Either<List<SavedRoute>, [SaveRouteFailure or UserAccountInfoFailure]>> {
    TODO()
I am trying to represent the fact that
[SaveRouteFailure or UserAccountInfoFailure]
as a single class, one idea I am trying is to create
Copy code
sealed interface SaveRouteRepositoryFailure: Failure
and trying to make
Copy code
sealed interface SaveRouteFailure : SaveRouteRepositoryFailure {
works
Copy code
sealed interface UserAccountInfoFailure : SaveRouteRepositoryFailure {
which can't be done because
account
repository doesn't depend on
savedroutes
. Have you had any experience in dealing with situations like above?
m
@Arun Joseph you can create a new type that unions the two..
Copy code
sealed class GetSavedRouteFailure(override val errorMessage: String) : Failure {
  data class UserAccountFailure(val value: UserAccountInfoFailure) : GetSavedRouteFailure(value.errorMessage)
  data class SaveRouteFailure(val value: SavedRouteFailure) : GetSavedRouteFailure(value.errorMessage)
}
a
Thanks @mitch I will try this out.
t
Im new to Arrow and FP in general however I thought Either was right biased to have the Failure on Left and Success On Right, @Arun Joseph if i am reading your definition correctly
Either<List<SavedRoute>, [SaveRouteFailure or UserAccountInfoFailure]>
, you have defined the opposite
m
and yeah it’s right biased, @Arun Joseph you should flip that List and Failure