Davide Giuseppe Farella
10/15/2022, 1:28 PMEither<NetworkError, T>
Something like
fun <T : Any> MyFun(
...
fetch: suspend () -> Either<NetworkError, T>,
...
): Flow<Either<DataError, T>>
Now I have a new use case, as I started supporting a guest mode, so besides NetworkError
and T
I need something to represent a case when the user is not logged in, which I don’t want to be part of either of the 2 mentioned.
What would you suggest to use instead of Either<NetworkError, T>
? ( Skipped
= call didn’t happen )
Here are some solutions that I thought of, but dunno which one would be nicer, or if there are other solutions:
• Either<Either<NetworkError, Skipped>, T>
this would be the easier one to achieve/refactor; not sure how nice it would be to nest 2 Either
• Either<NetworkResult, T>
sealed interface NetworkResult {
object Skipped : NetworkResult
data class Error(val networkError: NetworkError)
}
• Replace Either
with a sealed interface, like following
sealed interface NetworkResult<T> {
object Skipped : NetworkResult<Nothing>
data class Error<Nothing>(val networkError: NetworkError)
data class Data(val data: T)
}
The last solution is probably the cleanest, but I’d lose the Either
operators that I’m currently using, like tap
, fold
, bind
, etc
The second one would be my preferredDavide Giuseppe Farella
10/15/2022, 1:30 PMStore.kt
and PagedStore.kt
stojan
10/15/2022, 3:22 PMDavide Giuseppe Farella
10/15/2022, 4:07 PM