Easy idiomatic way to define Ordering for a simple case class

前端 未结 6 838
挽巷
挽巷 2020-11-30 17:34

I have a list of simple scala case class instances and I want to print them in predictable, lexicographical order using list.sorted, but receive \"No implicit O

6条回答
  •  隐瞒了意图╮
    2020-11-30 18:00

    The sortBy method would be one typical way of doing this, eg (sort on tag field):

    scala> l.sortBy(_.tag)foreach(println)
    A(article,2)
    A(lines,7)
    A(words,50)
    

提交回复
热议问题