Product Site

5.4.5.7.2. init

Initializes an InvertingComparator to sort strings using an inversion of the result from the comparator compare method.

Example 5.226. InvertingComparator class
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