A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/scala/scala3/issues/897 below:

Auto-tupling of n-ary functions. · Issue #897 · scala/scala3 · GitHub

Add the following automatic conversion:

Let

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) 

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4