Scala Tuple10隐式排序不起作用

时间:2016-03-23 04:31:48

标签: scala implicit

我可以比较方法工作到Tuple9如下:

  import scala.math.Ordered.orderingToOrdered
  (1,2,"ab",4,5,6.0,7l,"de",1.0) compare (1,2,"ab",4,5,6.0,7l,"de",1.0)

但是使用Tuple10我得到了编译错误:

  import scala.math.Ordered.orderingToOrdered
  (1,2,"ab",4,5,6.0,7l,"de",1.0,2) compare (1,2,"ab",4,5,6.0,7l,"de",1.0,2) // >> compile error: value compare is not a member of (Int, Int, String, Int, Int, Double, Long, String, Double, Int)

我尝试了替代方式,但这也给出了隐含错误:

implicitly[Ordering[Tuple10[Int, Int, String, Int, Int, Double, Long, String, Double, Double]]].compare((1,2,"ab",4,5,6.0,7l,"de",1.0,4), (1,2,"ab",4,5,6.0,7l,"de",1.0,4)) 

compiler error:
No implicit Ordering defined for (Int, Int, String, Int, Int, Double, Long, String, Double, Double).
not enough arguments for method implicitly: (implicit e: Ordering[(Int, Int, String, Int, Int, Double, Long, String, Double, Double)])Ordering[(Int, Int, String, Int, Int, Double, Long, String, Double, Double)]. Unspecified value parameter e.

看起来Ordering只定义为Tuple9。如果我错了,请纠正我。

1 个答案:

答案 0 :(得分:2)

source code可以看出,你是对的,它只适用于Tuple9。但是,在每次迭代中看到模式后,您应该能够根据需要进行复制和扩展。