Closed
Description
Add the following automatic conversion:
Let
F = (p1, ..., pn) => E
for n != 1
, parameters p1, ..., pn
, and an expression E
.
If the expected type of F
is a fully defined function type or SAM-type that has a
single parameter of a subtype of ProductN[T1, ..., Tn]
, where each type Ti
fits the corresponding
parameter pi
, then F
is rewritten to
x => {
def p1 = x._1
...
def pn = x._n
E
}
A type T
fits a parameter p
if one of the following two cases is true:
p
comes without a type, i.e. it is a simple identifier or_
.p
is of the formx: U
or_: U
andT
conforms toU
.
Auto-tupling composes with eta-expansion. That is an n-ary function generated by eta-expansion
can in turn be adapted to the expected type with auto-tupling.
Examples:
val pairs = List(1, 2, 3).zipWithIndex
pairs.map(_ + _)
def plus(x: Int, y: Int) = x + y
pairs.map(plus)