There is something that I cannot understand that someone can shed light on. I have a Seq [String]
val strDeps: Seq[String] = ...
and I tried sorting it in reverse using the sortWith method, and I get the following error.
scala> print(strDeps.sortWith(_.reverse.compareTo(_.reverse) < 0) mkString ("\n")) <console>:15: error: wrong number of parameters; expected = 2 print(strDeps.sortWith(_.reverse.compareTo(_.reverse) < 0) mkString ("\n")) ^
But when I try to sort it without doing the opposite, it works fine.
scala> print(strDeps.sortWith(_.compareTo(_) < 0) mkString ("\n")) // this is fine
It also works great without placeholder syntax
scala> print(strDeps.sortWith((a,b) => a.reverse.compareTo(b.reverse) < 0) mkString ("\n")) // this works fine too
source share