[swift-evolution] Add "maybe" keyword / Explicit Support for Ternary Logic

davesweeris at mac.com davesweeris at mac.com
Thu Jan 7 20:03:18 CST 2016


Does anyone else occasionally do stuff like this?
typealias Tern = Bool?
let maybe:Tern = nil

Personally, I’ve only needed it a couple times, but it seems like it could be useful. Maybe Tern should be its own enum instead of a typealias. 
Either way, aesthetically speaking, it’d be nice to have “maybe” be colored the same as “true” and “false”.

I’m not sure if there’s a generally agreed-upon ternary truth-table, especially for code like:
	if maybe == true {
		…
	} else {
		…
	}

(Come to think of it, didn’t someone suggest abandoning:
	if something == something_else {
		…
	} else {
		…
	}
in favor of:
	switch (something == something_else) {
	case true: …
	case false: …
	}
If so, that’d clean up the syntax since switches have to be exhaustive anyway… If a comparison results in a Tern you need to have a maybe case, if it results in a Bool you don’t.



Anyway, thoughts?




More information about the swift-evolution mailing list