Easy idiomatic way to define Ordering for a simple case class

前端 未结 6 847
挽巷
挽巷 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 17:51

    object A {
      implicit val ord = Ordering.by(unapply)
    }
    

    This has the benefit that it is updated automatically whenever A changes. But, A's fields need to be placed in the order by which the ordering will use them.

提交回复
热议问题