Skip to content

Instantly share code, notes, and snippets.

@tarunon
Created December 5, 2016 14:49
Show Gist options
  • Save tarunon/ef3eee8193e840f099a6e114453dccba to your computer and use it in GitHub Desktop.
Save tarunon/ef3eee8193e840f099a6e114453dccba to your computer and use it in GitHub Desktop.
It's small idea.
protocol TypedError: Error {
init(error: Error)
}
struct AnyError: TypedError {
let error: Error
init(error: Error) {
self.error = error
}
}
struct NoError: TypedError {
init(error: Error) {
fatalError("\(error)")
}
}
extension Observable {
func catchError<Er: TypedError, O: ObservableConvertible>(_ f: (Er) -> O) -> Observable where O.E == T {
return catchError { (error) in
return f(Er.init(error: error))
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment