Created
May 30, 2018 20:08
-
-
Save seivan/1c0fdffc8b16da92681a6a35c87c45f3 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
extension Either : Decodable where Right: Decodable, Left == Error { | |
public init(from decoder: Decoder) throws { | |
do { | |
let container = try decoder.singleValueContainer() | |
let value = try container.decode(Right.self) | |
self = .right(value) | |
} catch { | |
self = .left(error) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment