question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SIP: Auto-tupling of n-ary functions.

See original GitHub issue

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:

  1. p comes without a type, i.e. it is a simple identifier or _.
  2. p is of the form x: U or _: U and T conforms to U.

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:closed
  • Created 8 years ago
  • Comments:20 (15 by maintainers)

github_iconTop GitHub Comments

0reactions
som-snyttcommented, Jan 20, 2022

One fix is to change the migration doc from

Though it is possible that someone has written an implicit conversion form (T1, …, Tn) => R to TupleN[T1, …, Tn] => R for some n.

to

Users may wish to upgrade their implicit conversion from (T1, …, Tn) => R to TupleN[T1, …, Tn] => R to a given Conversion[(T1, ..., Tn) => R, TupleN[T1, ..., Tn] => R.

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” a transparent inline def apply, so there is an extra apply.

TIL TIL stands for transparent 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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found