Thanks!
One of the main patterns I found I was having to use was something like this:
enum Action {
case saveUser(User)
case saveUserResponse(Result<Never, Failure>)
}
extension Reducer where ... { state, action, env in
switch action {
case let .saveUser(user):
env.saveUser(user) // An AnyPublisher<Void, Failure>
.flatMap { _ in Empty<Never, Failure>() }
.catchToEffect()
.map(Action.saveUserResponse)
case let .saveUserResponse(.failure(failure)):
// Do something with failure
return .none
}
}
You don't have to handle the .success
case, because Swift knows it can't be constructed due to containing a Never
, but it was still extra typing and pain both to ignore the output, turn it into an effect, and include the .failure
in the resulting action. This approach appears to eliminate a lot of that extra typing