Scala: how can I sort an array of tuples by their second element?

后端 未结 7 734
悲&欢浪女
悲&欢浪女 2021-01-31 13:39

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

7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-31 14:39

    You probably want def stableSort[K](a : Seq[K], f : (K, K) => Boolean) : Array[K] from scala.util.Sorting.
    Your comparison function would be something like _._2 < _._1

提交回复
热议问题