Scala Tuple10 隐式排序不起作用
Scala Tuple10 implicit ordering not working
我可以得到 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.
似乎只为 Tuple9 定义了排序。如果我错了请纠正我。
从source code可以看出,你是对的,它只转到 Tuple9。但是在您看到每次迭代中的模式之后,您应该能够根据需要复制和扩展它。
我可以得到 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.
似乎只为 Tuple9 定义了排序。如果我错了请纠正我。
从source code可以看出,你是对的,它只转到 Tuple9。但是在您看到每次迭代中的模式之后,您应该能够根据需要复制和扩展它。