[swift-evolution] ? suffix for <, >, <=, >= comparisons with optionals to prevent subtle bugs
al_skipp at fastmail.fm
Wed Dec 9 05:10:29 CST 2015
> To me it seems logical that comparing Optional<Int> with Int (or another
> Optional<Int>), if it's allowed at all, should return Optional<Bool>. Since
> conditional statements only accept Bool, the user is forced to handle the
> nil case explicitly.
I disagree that comparing Optional values should have a return value of Optional<Bool>.
If the following were to be true:
.None < .Some(0) == .None
Then logically, this would be too:
 < [1,2,3] == 
I think most people would agree that the correct result to that comparison should be ‘true’, not .
When comparing ‘container’ types I think it’s important to have a simple Bool result, otherwise things get very peculiar (conceptually the Optional type is really just a container with a maximum count of 1).
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution