Given an Ordering[Seq[String]
like this:
new Ordering[Seq[String]]() {
override def compare(x: Seq[String], y: Seq[String]): Int = {
var i = 0
while (i < Math.min(x.size, y.size)) {
val c = x(i).compareTo(y(i))
if (c != 0) return c
i += 1
}
Integer.compare(x.size, y.size)
}
}
This sorts a Seq[Seq[String]]
according to the first String
that differs from the comparing sequence - or according to the sequences size if there are no differing String
s.
While this implementation works well, I would like to have an implementation without any var
s or return
s but cannot wrap my head around how to implement such a (more functional) ordering.