How to sort a list in Scala by two fields?
rows.sortBy (row => row.lastName + row.firstName)
If you want to sort by the merged names, as in your question, or
rows.sortBy (row => (row.lastName, row.firstName))
if you first want to sort by lastName, then firstName; relevant for longer names (Wild, Wilder, Wilderman).
If you write
rows.sortBy(_.lastName + _.firstName)
with 2 underlines, the method expects two parameters:
<console>:14: error: wrong number of parameters; expected = 1
rows.sortBy (_.lastName + _.firstName)
^
rows.sortBy(r => (r.lastName, r.firstName))