-
Notifications
You must be signed in to change notification settings - Fork 438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
["Request"] Keep handleErrorWith
function
#3122
Comments
Hey @PavlosTze, Thanks for the bug report! First of all, let's see if we can fix your snippets (for documentation purposes) In the first snippet, it's would need an additional override suspend fun getHourlyWeatherHistory(
deviceId: String,
date: LocalDate,
forceUpdate: Boolean
): Either<Failure, List<HourlyWeather>> {
return if (forceUpdate) {
Timber.d("Forced update. Skipping db.")
getHistoryFromNetwork(deviceId, date)
} else {
Timber.d("Non-forced update. Trying db first.")
getHistoryFromDatabase(deviceId, date)
.recover {
getHistoryFromNetwork(deviceId, date).bind()
}
}
} In the second snippet you're returning override suspend fun getSearchSuggestions(
query: String
): Either<Failure, List<SearchSuggestion>> {
return addressRepository.getSearchSuggestions(query)
.recover {
when (it) {
is CancellationError -> emptyList()
else -> raise(it)
}
}
} This way both snippets should compile, and work. Would be great if you could test them. I've been wondering a lot about val original: Either<String, Int> = "failure".left()
val x = original.recover { -1 } // cannot infer `Left`, should be `Either<Nothing, Int>`
val y: Either<Nothing, Int> = original.recover [ -1 } // is fine because of explicit type
val z = original.recover { raise(MyError) } // is fine because of builder inference Let's get some more opinions here, but I think we can consider keeping IMO Ideally Ithe Kotlin compiler could infer |
@nomisRev The first one isn't working properly. This way, the return result of:
is
returns an |
What version are you currently using?
What would you like to see?
I can see that
handleErrorWith
function is deprecated, I would like to ask to keep it as is. It seems way more complex to use therecover
functionality for some simple thins and I still haven't figured out how to do it in some instances e.g:If I use the suggestion from Android Studio the
getHistoryFromNetwork
doesn't return anEither
withrecover
, but returns aList<HourlyWeather>
.Also I can't make the following work with
recover
, compiler errors.The text was updated successfully, but these errors were encountered: