Skip to content

Instantly share code, notes, and snippets.

@seivan
Created May 30, 2018 20:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seivan/1c0fdffc8b16da92681a6a35c87c45f3 to your computer and use it in GitHub Desktop.
Save seivan/1c0fdffc8b16da92681a6a35c87c45f3 to your computer and use it in GitHub Desktop.
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