[swift-evolution] [Idea] Bringing the partial/total ordering distinction into Comparable
Dave Abrahams
dabrahams at apple.com
Mon Apr 25 18:08:03 CDT 2016
on Sun Apr 24 2016, Brent Royal-Gordon <swift-evolution at swift.org> wrote:
>> Regarding how this affects sorting methods though, some people (myself included) like the simplicity of being able to do the following:
>>
>> myArray.sort(>) // If array is of Comparable elements, just throw in the operator
>
> That is extremely convenient. With my proposed extensions, it's actually writeable as this:
>
> myArray.sorted { ($0 <=> $1).reversed() }
>
> But that's obviously much less convenient. It's also equivalent to this:
>
> myArray.sorted { $1 <=> $0 }
>
> Which means, with the proper higher-order function, it's the same as this:
>
> myArray.sorted(flip(<=>))
There's no reason we can't accept both kinds of ordering function, though it
does expand the overload set, which is a usability downside.
--
Dave
More information about the swift-evolution
mailing list