scala someFn.tupled
works when calling with anonymous named tuples, example
val point = (x = 1.0, y = 2.0)
however if the named tuple was defined with a type alias like
type Point = (x: Double, y: Double)
val point: Point = (x = 1.0, y = 2.0)
then compilation breaks when point
is passed to someFn.tupled
Here is an full example you can test in a scala 3.5 worksheet, notice that testA
and testB
are the same tuple reference, but the second used type alias
type Rekto = (x: Double, y: Double, w: Double, h: Double, l: Boolean)
val testA = (x = 1.0, y = 2.0, w = 3.0, h = 4.0, l = true)
val testB: Rekto = testA // <= same as testA
def pinta(x: Double, y: Double, w: Double, h: Double, l: Boolean): Unit =
println(s"pinta: $x, $y, $w, $h, $l")
// WORKS
pinta.tupled(testA)
// DOES NOT WORK
// Found: (MdocApp.this.testB : MdocApp.this.Rekto)
// Required: (Double, Double, Double, Double, Boolean)
pinta.tupled(testB)