Skip to content

Commit 1e9499c

Browse files
committed
Mention general conversions for untupling
1 parent aea38cf commit 1e9499c

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

docs/docs/reference/other-new-features/parameter-untupling-spec.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,12 @@ is feasible for parameter untupling with the expected type `TupleN[T1, ..., Tn]
7777
with the same expected type.
7878
## Migration
7979

80-
Code like this could not be written before, hence the new notation would not be ambiguous after adoption.
80+
Code like this could not be written before, hence the new notation is not ambiguous after adoption.
8181

82-
Though it is possible that someone has written an implicit conversion form `(T1, ..., Tn) => R` to `TupleN[T1, ..., Tn] => R`
83-
for some `n`. This change could be detected and fixed by [`Scalafix`](https://scalacenter.github.io/scalafix/). Furthermore, such conversion would probably
84-
be doing the same translation (semantically) but in a less efficient way.
82+
It is possible that someone has written an implicit conversion from `(T1, ..., Tn) => R` to `TupleN[T1, ..., Tn] => R` for some `n`.
83+
Such a conversion is now only useful for general conversions of function values, apart from the adaptation described here.
84+
Some care is required to implement the conversion efficiently.
85+
Obsolete conversions could be detected and fixed by [`Scalafix`](https://scalacenter.github.io/scalafix/).
8586

8687
## Reference
8788

docs/docs/reference/other-new-features/parameter-untupling.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,26 @@ Generally, a function value with `n > 1` parameters is converted to a
3838
pattern-matching closure using `case` if the expected type is a unary
3939
function type of the form `((T_1, ..., T_n)) => U`.
4040

41+
More specifically, the adaptation is applied to the mismatching formal
42+
parameter list. In particular, the adaptation is not a conversion
43+
between function types. That is why the following is not accepted:
44+
45+
```scala
46+
val combine: (Int, Int) => Int = _ + _
47+
xs.map(combine)
48+
```
49+
50+
An explicit conversion for this case may be provided in user code, as usual:
51+
52+
```scala
53+
import scala.language.implicitConversions
54+
inline transparent implicit def `enable untupling`(f: (Int, Int) => Int): ((Int, Int)) => Int =
55+
p => f(p._1, p._2)
56+
xs.map(combine)
57+
```
58+
59+
The implicit adaptation is attempted before conversions are applied.
60+
4161
## Reference
4262

4363
For more information see:

0 commit comments

Comments
 (0)