Created
December 5, 2016 14:49
-
-
Save tarunon/ef3eee8193e840f099a6e114453dccba to your computer and use it in GitHub Desktop.
It's small idea.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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