Created
February 25, 2021 09:02
-
-
Save JensAyton/92167cdbff1dfd7efd9e6c16be533241 to your computer and use it in GitHub Desktop.
A very useful type
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
enum Tristate: ExpressibleByNilLiteral, ExpressibleByBooleanLiteral { | |
case maybe | |
case no | |
case yes | |
init(nilLiteral: Void) { | |
self = .maybe | |
} | |
init(booleanLiteral value: Bool) { | |
self = value ? .yes : .no | |
} | |
} | |
let a: Tristate = nil // .maybe | |
let b: Tristate = false // .no | |
let c: Tristate = true // .yes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment