Last active
January 11, 2022 12:53
-
-
Save pietrobasso/7d74d81837c1729da8ffb5ac0fa93f2c to your computer and use it in GitHub Desktop.
Throwable
This file contains hidden or 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
struct Throwable<T: Decodable>: Decodable { | |
private let result: Result<T, Error> | |
init(from decoder: Decoder) throws { | |
do { | |
result = .success(try T(from: decoder)) | |
} catch let error { | |
// additionally, logError(error) | |
result = .failure(error) | |
} | |
} | |
func get() -> T? { | |
try? result.get() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment