[swift-evolution] [pitch] Comparison Reform

Dave Abrahams dabrahams at apple.com
Sat Apr 15 14:44:17 CDT 2017

on Thu Apr 13 2017, Jonathan Hull <swift-evolution at swift.org> wrote:

> I still like the ordering of floats defined in this proposal best (and
> think we should use it), but I imagine that there are other types
> which are almost (but not quite) comparable as well. Would there be
> any utility in having a ‘PartialComparable’ protocol that defined a
> single method:
> 	func compare(_:)->ComparisonResult?
> That is, it is just like our compare, but it returns nil if two values
> can’t be meaningfully compared.  It would force you to deal with the
> cases where the comparison didn’t make sense, and handle it in a
> reasonable way in your code. (e.g. filtering those values out, or
> sticking them at the end).
> You can think of it as failable compare...

The first question when proposing a new protocol is always: what generic
algorithm can take advantage of this API?


More information about the swift-evolution mailing list