I'm trying to sort an array of objects. When i try to use sortWith function to sort only one field in the object, it works perfectly fine. When multiple fields are sorted, then it messes up.
For eg.
scala> val res = branches.collect.toList
res: Array[(String, String, String)] = Array((109,A,Australia), (101,A,Australia), (102,A,Myanmar), (103,B,Australia), (104,A,Europe), (105,B,US), (106,B,Myanmar), (107,C,Australia), (108,A,Canada))
scala> val a = res.sortWith((x,y) => (x._2 < y._2 && x._1 > y._1))
Basically im trying to sort 2nd tuple and based on the result i'm sorting the first tuple. I get the following result, which is not sorted properly. I understand that the same can be achieved with sortBy function also. But i would like to understand how the sortWith works.
scala> val a = res.sortWith((x,y) => (x._2 < y._2 && x._1 > y._1))
a: Array[(String, String, String)] = Array((109,A,Australia), (107,C,Australia), (101,A,Australia), (102,A,Myanmar), (104,A,Europe), (108,A,Canada), (103,B,Australia), (105,B,US), (106,B,Myanmar))