A RetroSearch Logo

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

Search Query:

Showing content from https://docs.scala-lang.org/scala3/reference/changed-features/vararg-splices.html below:

Vararg Splices

Edit this page on GitHub Vararg Splices

The syntax of vararg splices in patterns and function arguments has changed. The new syntax uses a postfix *, analogously to how a vararg parameter is declared.

val arr = Array(0, 1, 2, 3)
val lst = List(arr*)                   // vararg splice argument
lst match
  case List(0, 1, xs*) => println(xs)  // binds xs to Seq(2, 3)
  case List(1, _*) =>                  // wildcard pattern

The old syntax for splice arguments will be phased out.

/*!*/ val lst = List(arr: _*)      // syntax error
      lst match
        case List(0, 1, xs @ _*)  // ok, equivalent to `xs*`
Syntax
ArgumentPatterns  ::=  ‘(’ [Patterns] ‘)’
                    |  ‘(’ [Patterns ‘,’] Pattern2 ‘*’ ‘)’

ParArgumentExprs  ::=  ‘(’ [‘using’] ExprsInParens ‘)’
                    |  ‘(’ [ExprsInParens ‘,’] PostfixExpr ‘*’ ‘)’
Compatibility considerations

To enable cross compilation between Scala 2 and Scala 3, the compiler will accept both the old and the new syntax. Under the -source future setting, an error will be emitted when the old syntax is encountered. An automatic rewrite from old to new syntax is offered under -source future-migration.


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