A direct solution in this particular case is to use sortBy in tuples modified on the fly to “invert” the first and second elements so that the order is finally canceled:
val a = Array((false, 8, "zz"), (false,3, "bb"), (true, 5, "cc"),(false, 3,"dd")) a.sortBy{ case (x,y,z) => (!x, -y, z) }
In cases where you cannot easily “invert” the value (say that it is a reference object and you have an opaque order on them), you can instead use sorted and explicitly pass the ordering that is built to invert the order on the first and second elements (you can use Ordering.reverse to reverse the order):
val myOrdering: Ordering[(Boolean, Int, String)] = Ordering.Tuple3(Ordering.Boolean.reverse, Ordering.Int.reverse, Ordering.String) a.sorted(myOrdering)
source share