Skip to content

Instantly share code, notes, and snippets.

@pietrobasso
Last active January 11, 2022 12:53
Show Gist options
  • Save pietrobasso/7d74d81837c1729da8ffb5ac0fa93f2c to your computer and use it in GitHub Desktop.
Save pietrobasso/7d74d81837c1729da8ffb5ac0fa93f2c to your computer and use it in GitHub Desktop.
Throwable
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