Skip to content

Instantly share code, notes, and snippets.

@walteh
Last active July 20, 2024 23:29
Show Gist options
  • Save walteh/cf897ac832cc27aab4c1583b4f6d64b0 to your computer and use it in GitHub Desktop.
Save walteh/cf897ac832cc27aab4c1583b4f6d64b0 to your computer and use it in GitHub Desktop.
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