Last active
May 2, 2020 02:37
-
-
Save eMdOS/538393d3ef320b5ae28bed1a50a8c207 to your computer and use it in GitHub Desktop.
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
public protocol DecodableDataDecoder { | |
func decode<T>(_ type: T.Type, from data: Data) throws -> T where T: Decodable | |
} | |
extension JSONDecoder: DecodableDataDecoder {} | |
extension PropertyListDecoder: DecodableDataDecoder {} | |
public extension Result where Success == Data { | |
func decode<T: Decodable>(_ type: T.Type, using decoder: DecodableDataDecoder) -> Result<T, Error> { | |
do { | |
return .success(try decoder.decode(type, from: try get())) | |
} catch { | |
return .failure(error) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment