+ fun compare(a: COMPARED, b: COMPARED): Int is abstract
+
+ # Is `seq` sorted?
+ #
+ # assert default_comparator.is_sorted([1,2,2,3]) == true
+ # assert default_comparator.is_sorted([1,10,2,3]) == false
+ # assert alpha_comparator.is_sorted([1,10,2,3]) == true
+ fun is_sorted(seq: SequenceRead[COMPARED]): Bool
+ do
+ if seq.length <= 1 then return true
+ var prev = seq.first
+ for e in seq do
+ if compare(prev, e) > 0 then return false
+ prev = e
+ end
+ return true
+ end
+
+ # Returns the minimum between `a` and `b`.
+ #
+ # assert default_comparator.min(2,10) == 2
+ # assert alpha_comparator.min(2,10) == 10
+ #
+ # If both are equivalent, then returns `a`.
+ #
+ # var m = alpha_comparator.min(1, "1")
+ # assert m == 1
+ # assert m != "1"
+ fun min(a,b: COMPARED): COMPARED
+ do
+ if compare(a,b) > 0 then return b else return a
+ end
+
+ # Returns the maximum between `a` and `b`.
+ #
+ # assert default_comparator.max(2,10) == 10
+ # assert alpha_comparator.max(2,10) == 2
+ #
+ # If both are equivalent, then returns `a`.
+ #
+ # var m = alpha_comparator.max(1, "1")
+ # assert m == 1
+ # assert m != "1"
+ fun max(a,b: COMPARED): COMPARED
+ do
+ if compare(a,b) < 0 then return b else return a
+ end