попробуйте ниже код:
val names = List(("Jack","Wilson"),("Alex","Jao"),("Jack","Wildorsowman"),
("Jack","Wiliamson"),("Alex","Joan"),("Alex","J."))
println(names.sortBy( x => (x._1.length(),x._2.length())))
Результат:
List((Alex,J.), (Alex,Jao), (Alex,Joan), (Jack,Wilson), (Jack,Wiliamson), (Jack,Wildorsowman))
ОБНОВЛЕНО по предложению @GalNaor -
val names = `List(List("Jack","Wilson"),List("Alex","Jao"),List("Jack","Wildorsowman"),List("Jack","Wiliamson"),List("Alex","Joan"),List("Alex","J."))`
println(names.sortBy{ case List(x,y) => (x.length(),y.length())})
Результат:
List(List(Alex, J.), List(Alex, Jao), List(Alex, Joan), List(Jack, Wilson), List(Jack, Wiliamson), List(Jack, Wildorsowman))