Search code examples
scalaimplicit

Scala Tuple10 implicit ordering not working


I can get compare method work upto Tuple9 like following:

  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)

But with Tuple10 I get compile error:

  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)

I tried alternate way but that also gives implicit error:

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.

Looks like Ordering is defined for only till Tuple9. Correct me if I am wrong.


Solution

  • As you can see from the source code, you are correct, it only goes to Tuple9. But after you've seen the pattern in each iteration you should be able to copy and extend it as needed.