I need to have an equivalent of the compareWith(a,b) method in Java, in Scala.
I have a list of strings and I need to sort them by comparing them with each other. sortBy just takes one string and returns a score, but that's not enough in my case, i need to compare two strings with each other and then return a number based on which one is better.
It seems like the only option is to write a custom case class, convert the strings to it, and then covert them back. For performance reasons, I want to avoid this as I have a large amount of data to process.
Is there a way to do this with just the strings?
compareWith()? I'm having a hard time finding the documentation for that. Can you provide a link? Also, I'm not sure what's wrong with"abc" compareTo "xyz". Please clarify.compareTorather than with, I haven't used java in a while. And what's wrong is that I need to write my own rules for the comparison.compareTo(), I guess I still don't understand your objections and/or requirements. When it comes to sorting aList[String], you can.sortWith(_.compareTo(_)<0)(which you seem to like), or you can.sortBy(s=>s)(which is shorter), or you can.sorted(which is direct and to the point).