SIP: Auto-tupling of n-ary functions.
See original GitHub issueAdd 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)
Issue Analytics
- State:
- Created 8 years ago
- Comments:20 (15 by maintainers)
Top Results From Across the Web
SIP Header Addition Functions - SIPAPI Developer's Guide
The sip_add_header() function takes a SIP header string as the second argument and appends it to the SIP message. This function creates the...
Read more >What is Session Initiation Protocol (SIP)? A definition from ...
SIP features. The SIP communications protocol determines five attributes when establishing and terminating multimedia sessions: user location; user availability ...
Read more >Pre-SIP: Suspended functions and continuations in Scala 3
Pre-SIP: Suspended functions and continuations in Scala 3. This Pre-SIP post proposes continuations as a new language feature in Scala 3.
Read more >Python SIP expose function - c++ - Stack Overflow
I'm writing a Python module for some C++ code using SIP. However whilst I can easily expose classes, I cannot find a way...
Read more >User-Defined Functions :: SIP3 Documentation
SIP3 User-Defined Functions. ... At the same time it gives you a card blanche for modifying each SIP message ... User-Defined Function Base...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@julienrf https://docs.scala-lang.org/scala3/reference/other-new-features/parameter-untupling-spec.html
One fix is to change the migration doc from
to
Actually, the naive
implicit transparent inline def
conversion does the obvious, efficient thing.It’s OK to
transparent inline given Conversion
but you can’t “nest” atransparent inline def apply
, so there is an extraapply
.TIL
TIL
stands fortransparent inline love
.Update: I did PR the explanation on the doc page. Unfortunately, it is not as droll as my comment here. Thanks @julienrf for raising awareness.
This issue or edge case is similar to the issue about rewrapping context functions: the adaptation is syntax-driven, or is a function of syntax, so it’s a surprise that it is not type-driven.