[swift-evolution] [Review] Tuple comparison operators (was: Add a Lazy flatMap for Sequences of Optionals)

Guillaume Lessard glessard at tffenterprises.com
Tue Dec 22 20:28:48 CST 2015

> On 22 déc. 2015, at 18:11, Dave Abrahams <dabrahams at apple.com> wrote:
> Yes, the mathematical definition of lexicographical order (the only definition that can apply here) is the same everywhere.

Okay. I got sidetracked by “lexicography”. I like to buy dictionaries.

This converges on the problem, though: this-precedes-that is *not* the same as this-is-less-than-that.
(Maybe we were talking about different things.)

Note the signature of sort:
func sort(isOrderedBefore: (T, T) -> Bool) -> [T]

Not “lessThan”, but “isOrderedBefore”.

This proposal would redefine the less-than operator to mean “isOrderedBefore”.
It’s been done with String for the sake of convenience, but it should not be generalized.
(Again, a function isOrderedBefore<NTupleOfComparables>(t1,t2) would be useful.)

Note that there is a proper definition of less-than for vectors. (tuples being generalized vectors).
Under that definition, *every* element of vector 1 must be less-than the corresponding elements of vector 2 in order to establish that vector 1 is less-than vector 2.
Back to my example: ((0,3,4)<(0,5,0)) is false and ((0,3,4)>(0,5,0)) is false.
One may well be ordered before the other.

Guillaume Lessard

More information about the swift-evolution mailing list