1
votes

From Magnet Pattern article, I found implicit conversion special pattern.

What is interesting is that this approach also works for “overloads” with more than one parameter just as well as different return types. If you call complete with several arguments the compiler looks for an implicit conversion that can produce a magnet instance from a tuple wrapping all arguments. This way overloads with up to 22 parameters (the maximum arity of tuples in scala) can be supported.

scala> def printInt(i: Int) = println(i)
printInt: (i: Int)Unit

scala> printInt(10)
10

scala> printInt(10, 20)
                    ^
       error: too many arguments (2) for method printInt: (i: Int)Unit

scala> implicit def toOneInt(is: (Int, Int)): Int = is._1 + is._2
warning: there was one feature warning; for details, enable `:setting     -feature' or `:replay -feature'
toOneInt: (is: (Int, Int))Int

scala> printInt((10, 20))
30

scala> printInt(10, 20)
30

printInt((10, 20)) is boring me, but printInt(10, 20) is awesome!

Then I sought the specification of this special pattern from Scala Language Specification (2.12). However I cannot find it yet and finally give up.

Could anyone show me where is the special pattern from Scala Language Specification (2.12) ?

1

1 Answers

0
votes

By xuwei_k help, finally I reached name of the feature "adapted args" or "auto tupling". For further details, Scala Puzzle(jp) was so helpful.

And also Scala Puzzlers shows [SI-3583] Spec doesn't mention automatic tupling - Scala.

Then, the answer is nowhere yet.