Created
March 22, 2021 15:07
-
-
Save stleamist/5c666654cc3620c29f0be24a66ad4ad5 to your computer and use it in GitHub Desktop.
This file contains 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
import Swift | |
extension Result { | |
func casting<NewSuccess, NewFailure>() -> Result<NewSuccess, NewFailure>? { | |
switch self { | |
case .success(let success as NewSuccess) where Failure.self is NewFailure.Type: return .success(success) | |
case .failure(let failure as NewFailure) where Success.self is NewSuccess.Type: return .failure(failure) | |
default: return nil | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment