如何按两个字段对 Scala 中的列表进行排序,在本例中,我将按姓氏和名字排序?
case class Row(var firstName: String, var lastName: String, var city: String)
var rows = List(new Row("Oscar", "Wilde", "London"),
new Row("Otto", "Swift", "Berlin"),
new Row("Carl", "Swift", "Paris"),
new Row("Hans", "Swift", "Dublin"),
new Row("Hugo", "Swift", "Sligo"))
rows.sortBy(_.lastName)
我尝试这样的事情
rows.sortBy(_.lastName + _.firstName)
但它不起作用。所以我很好奇一个好的和简单的解决方案。