I am trying to sort a list of tuples in Scala, the following code will result in error:
List("a"->1,"b"->2, "c"->3).sortBy(-_._1)
error: diverging implicit expansion for type scala.math.Ordering[B]
starting with method Tuple9 in object Ordering
List("a"->1,"b"->2, "c"->3).sortBy(-_._1)
^
but the code below works just fine:
List("a"->1,"b"->2, "c"->3).sortBy(_._1)
res39: List[(String, Int)] = List((a,1), (b,2), (c,3))
The only difference is the negative sign in sortBy!
What is the problem?