Created
November 20, 2024 04:43
-
-
Save abhi21git/457789633fae378f334c124cd2e415c4 to your computer and use it in GitHub Desktop.
Extends the functionality of Result<Success, Error>
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
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