Sort using a custom comparator: Difference between revisions

Content added Content deleted
Line 162: Line 162:
=={{header|AppleScript}}==
=={{header|AppleScript}}==


AppleScript is not itself well equipped with sorting functions, but from Yosemite onwards we can make some use of ObjC classes. While a classic comparator function can not readily be passed from AppleScript to ObjC, we can at least write a custom function which lifts atomic values into records with keys to base and derivative values, and also passes a sequence of (key, bool) pairs, where the bool expresses the choice between ascending and descending order for the paired key:
AppleScript is not itself well equipped with sorting functions, but from Yosemite onwards we can make some use of ObjC classes. While a classic comparator function can not readily be passed from AppleScript to ObjC, we can at least write a custom function which lifts atomic values into records (with keys to base and derivative values), and also passes a sequence of (key, bool) pairs, where the bool expresses the choice between ascending and descending order for the paired key:


<lang AppleScript>use framework "Foundation"
<lang AppleScript>use framework "Foundation"