On 9/16/11 11:29 AM, Andrei Alexandrescu wrote:
On 9/16/11 9:38 AM, bearophile wrote:
Jonathan M Davis:

Comparator functions are pretty much always binary predicates.

And I think this has to change a bit in D. Because mapping functions
are quite handy (despite requiring more memory, so it can't be the
only way to do things in D, and both ways need to be supported).

In Python3 sort/sorted/min/max don't take a comparator function, they
only take a key mapping function.

It's often used in Haskell too:

import Data.List (sortBy) import Data.Ord (comparing) main = print $
sortBy (comparing length) [[1,3,1], [5], [7,7]]

Yah, that's what SQL's order by does too.

To sort numbers descending one would sort by mapping through "-a", to
sort case-insensitive one would sort by mapping through "toupper(a)" etc.

I just figured an annoying case for sort through mapping: how would one sort a range of ulong descending? Or a range of pointers for that matter?

Andrei

Reply via email to