Created
February 23, 2021 23:00
-
-
Save CassiusPacheco/4378d30d69316e4a6ba28a0c3af72628 to your computer and use it in GitHub Desktop.
This abstraction contains either a success data of generic type `T` or an error of type `ErrorCode` as its result.
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
enum ErrorCode: Equatable, Error { | |
case unknown | |
// Top level server error | |
case serverIssue | |
// Network | |
case noNetworkConnection | |
} | |
enum DataResult<T> { | |
case success(value: T) | |
case error(ErrorCode) | |
var value: T? { | |
switch self { | |
case .success(value: let value): | |
return value | |
case .error: | |
return nil | |
} | |
} | |
var error: ErrorCode? { | |
switch self { | |
case .success: | |
return nil | |
case let .error(error): | |
return error | |
} | |
} | |
} | |
extension DataResult: Equatable where T: Equatable {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment