InvertingComparator to sort
strings using an inversion of the result from the
comparator compare method.
wine = .Array~of("1. Strawberries", "2. cherries", "3. angel's kiss")
wine~sortWith(.InvertingComparator~new(.LengthComparator~new))
-- 3. angel's kiss, 1. Strawberries, 2. cherries
-- compare 1. by length, 2. by standard comparison
::class LengthComparator mixinclass Comparator public
::method compare
use strict arg left, right
lengthDelta = left~length - right~length
if lengthDelta = 0 then
return left~compareTo(right)
else
return lengthDelta~sign