[swift-evolution] [Accepted] SE-0121: Remove Optional Comparison Operators
Haravikk
swift-evolution at haravikk.me
Sun Aug 28 08:23:54 CDT 2016
> On 28 Aug 2016, at 14:04, Tino Heth <2th at gmx.de> wrote:
>
>
>> Am 28.08.2016 um 05:34 schrieb Kevin Ballard via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>>:
>>
>>> My biggest issue with Optional conforming to Comparable is that while a default implementation may sometimes be useful, it may not necessarily be the one you want.
>>
>> Isn't that true for almost everything?
>
> That reminds me on a feature that has been discussed and added before:
> Making tuples conform to Comparable (https://github.com/apple/swift-evolution/blob/master/proposals/0015-tuple-comparison-operators.md <https://github.com/apple/swift-evolution/blob/master/proposals/0015-tuple-comparison-operators.md>)
> The implementation doesn't hurt me, but imho it's use is very limited as well.
>
> As for comparing optionals, my preferred result would be an Optional<Bool>:
> if (value < 5) ?? true {…
> It makes no assumptions on the order, is clear and also concise.
>
> Tino
This could be an interesting compromise, but I'd say it shouldn't use the same operator as it's meaning differs from the norm, but in that case you'd be looking at introducing <?, >? etc. which is a lot of new operators for the task (which the Swift team I think wants to avoid).
As others have said, the proposal for a strict ordering operator ought to solve most of these issues, so it should probably be made a priority, as with it we can have strictly ordered, optional types, where the meaning of < (inferred from the strict ordering operator) is well defined, which ought to cover most types that will implement it.
Otherwise I'd say your options are either to use nil coalescing (??) or re-implement the optional forms of the operators yourself where necessary (and deal with later once strict ordering is added). I think for most cases right now this should be sufficient; disruptive admittedly, but the best option for now IMO.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160828/aa5a7f00/attachment.html>
More information about the swift-evolution
mailing list