How to lexicographically compare scala tuples?

后端 未结 3 2048
暗喜
暗喜 2020-12-14 08:54

Given two tuples of the same arity, how can I lexicographically compare them? It seems like this should be as simple as in the following snippet, but it isn\'t. Any simple e

3条回答
  •  情深已故
    2020-12-14 09:51

    Daniel's solution works if you want to use < but if you need a compare method you can do the following (for example).

    implicitly[Ordering[Tuple2[Int, Int]]].compare((1,2), (2,3))
    

    There are orderings defined for all tuples with comparable parts.

提交回复
热议问题