Add ordering ex

master
Mike Gerber 8 years ago
commit cff314486c

@ -0,0 +1,22 @@
import scala.math.Ordering.IntOrdering
// Define instantiable integer orderings
class RealIntOrdering extends IntOrdering {}
class ReverseIntOrdering extends Ordering[Int] {
val realIntOrdering = new RealIntOrdering()
def compare(x: Int, y: Int): Int = -realIntOrdering.compare(x, y)
}
// Test stuff
val values = List(1,2,6,3,4)
val ord: Ordering[Int] = new RealIntOrdering()
values.min(cmp = ord)
values.sorted(ord = ord)
val reverseOrd = new ReverseIntOrdering()
values.min(cmp = reverseOrd)
values.sorted(ord = reverseOrd)
Loading…
Cancel
Save