What's the best way to inverse sort in scala?

前端 未结 9 1833
感情败类
感情败类 2020-12-12 10:11

What is the best way to do an inverse sort in scala? I imagine the following is somewhat slow.

list.sortBy(_.size).reverse

Is there a conv

9条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-12 10:43

    maybe to shorten it a little more:

    def Desc[T : Ordering] = implicitly[Ordering[T]].reverse
    
    List("1","22","4444","333").sortBy( _.size )(Desc)
    

提交回复
热议问题