Example 5.175. Array class - sorting
myArray = .array~of("Zoe", "Fred", "Xavier", "Andy") myArray~sort do name over myArray say name end
Example 5.176. Non-string sorting
::class Employee inherit Comparable ::attribute id ::attribute name ::method init expose id name use arg id, name ::method compareTo expose id use arg other return id~compareTo(other~id) -- comparison performed using employee id ::method string expose name return "Employee" name
Example 5.177. Comparison during sorting
a = .array~new a[1] = .Employee~new(654321, "Fred") a[2] = .Employee~new(123456, "George") a[3] = .Employee~new(333333, "William") a~sort do employee over a say employee -- sorted order is "George", "William", "Fred" end