【问题标题】:Scala Tuple10 implicit ordering not workingScala Tuple10 隐式排序不起作用
【发布时间】:2016-03-23 04:31:48
【问题描述】:

我可以让比较方法工作到 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 之前定义。如果我错了,请纠正我。

【问题讨论】:

    标签: scala implicit


    【解决方案1】:

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

    【讨论】:

    • 谢谢。添加此类扩展的最佳位置是什么。我知道在一个范围内它是可用的,但是为了使它更加全球化,将它放在一些实用程序对象中并进行隐式导入会更好吗?
    猜你喜欢
    • 2014-11-02
    • 2018-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-17
    • 1970-01-01
    相关资源
    最近更新 更多