Skip to content

Instantly share code, notes, and snippets.

@abhi21git
Created November 20, 2024 04:43
Show Gist options
  • Save abhi21git/457789633fae378f334c124cd2e415c4 to your computer and use it in GitHub Desktop.
Save abhi21git/457789633fae378f334c124cd2e415c4 to your computer and use it in GitHub Desktop.
Extends the functionality of Result<Success, Error>
fileprivate extension Result {
func get() throws -> Success {
switch self {
case .success(let value): return value
case .failure(let error): throw error
}
}
var data: Success? {
return switch self {
case .success(let value): value
case .failure: nil
}
}
var error: Failure? {
return switch self {
case .success: nil
case .failure(let error): error
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment