Last active
July 20, 2024 23:29
-
-
Save walteh/cf897ac832cc27aab4c1583b4f6d64b0 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
public extension Result { | |
// Extract the value if it's a success | |
var value: Success? { | |
switch self { | |
case let .success(value): | |
return value | |
case .failure: | |
return nil | |
} | |
} | |
// Extract the error if it's a failure | |
var error: Failure? { | |
switch self { | |
case .success: | |
return nil | |
case let .failure(error): | |
return error | |
} | |
} | |
} | |
public extension Result { | |
func into(_ err: inout Error?) -> (Success?) { | |
switch self { | |
case let .success(value): | |
return value | |
case let .failure(error): | |
err = error | |
return nil | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment