is there a way in Scala to sort an array of tuples using and arbitrary comparison function? In particular I need to sort and array of tuples by their second element, but I wante
On Scala 2.8 (yes, again :), you can also do this:
val v = Array(('a', 2), ('b', 1))
scala.util.Sorting.stableSort(v)(manifest[(Char, Int)], Ordering.by(_._2))
In the specific case of pairs, this can also work to sort first by the second element, and then by the first:
scala.util.Sorting.stableSort(v)(manifest[(Char, Int)], Ordering.by(_.swap))