You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/docs/reference/changed/vararg-patterns.md
+35-42Lines changed: 35 additions & 42 deletions
Original file line number
Diff line number
Diff line change
@@ -3,45 +3,38 @@ layout: doc-page
3
3
title: "Vararg Patterns"
4
4
---
5
5
6
-
The syntax of vararg patterns has changed. In the new syntax one
7
-
writes varargs in patterns exactly like one writes them in
8
-
expressions, using a `: _*` type annotation:
9
-
10
-
xs match {
11
-
case List(1, 2, xs: _*) => println(xs) // binds xs
12
-
case List(1, _ : _*) => // wildcard pattern
13
-
}
14
-
15
-
The old syntax, which is shorter but less regular, is no longer
16
-
supported:
17
-
18
-
/*!*/ case List(1, 2, xs @ _*) // syntax error
19
-
/*!*/ case List(1, 2, _*) => ... // syntax error
20
-
21
-
Another change relates to extractors producing values with `T*` types, which can then be
22
-
matched by vararg patterns. Previously, such extractors used an `unapplySeq` whereas now they use an `unapply` (in the long term, we plan to get rid of `unapplySeq` altogether, replacing all its usages with `unapply`).
23
-
24
-
Example: Previously, this was correct:
25
-
26
-
class Person(val name: String, val children: Person *)
0 commit comments