How make implicit Ordered on java.time.LocalDate

前端 未结 5 734
故里飘歌
故里飘歌 2021-01-04 00:33

I want to use java.time.LocalDate and java.time.LocalDateTime with an implicit Ordered like:

val date1 = java.time.Loc         


        
5条回答
  •  醉梦人生
    2021-01-04 01:12

    You can use Ordering.by to create ordering for any type, given a function from that type to something that already has an Ordering - in this case, to Long:

    implicit val localDateOrdering: Ordering[LocalDate] = Ordering.by(_.toEpochDay)
    

提交回复
热议问题