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-features/match-syntax.md
+33-31Lines changed: 33 additions & 31 deletions
Original file line number
Diff line number
Diff line change
@@ -6,45 +6,47 @@ title: Match Expressions
6
6
The syntactical precedence of match expressions has been changed.
7
7
`match` is still a keyword, but it is used like an alphabetical operator. This has several consequences:
8
8
9
-
1.`match` expressions can be chained:
9
+
1.`match` expressions can be chained:
10
+
11
+
```scala
12
+
xs match {
13
+
caseNil=>"empty"
14
+
case x :: xs1 =>"nonempty"
15
+
} match {
16
+
case"empty"=>0
17
+
case"nonempty"=>1
18
+
}
19
+
```
20
+
21
+
(or, dropping the optional braces)
22
+
23
+
```scala
24
+
xs match
25
+
caseNil=>"empty"
26
+
case x :: xs1 =>"nonempty"
27
+
match
28
+
case"empty"=>0
29
+
case"nonempty"=>1
30
+
```
31
+
32
+
2.`match` may follow a period:
10
33
11
34
```scala
12
-
xs match {
13
-
caseNil=>"empty"
14
-
case x :: xs1 =>"nonempty"
15
-
} match {
16
-
case"empty"=>0
17
-
case"nonempty"=>1
18
-
}
35
+
if xs.match
36
+
caseNil=>false
37
+
case _ =>true
38
+
then"nonempty"
39
+
else"empty"
19
40
```
20
41
21
-
(or, dropping the optional braces)
22
-
23
-
```scala
24
-
xs match
25
-
caseNil=>"empty"
26
-
case x :: xs1 =>"nonempty"
27
-
match
28
-
case"empty"=>0
29
-
case"nonempty"=>1
30
-
```
31
-
32
-
2. `match` may follow a period:
33
-
34
-
```scala
35
-
if xs.match
36
-
caseNil=>false
37
-
case _ =>true
38
-
then"nonempty"
39
-
else"empty"
40
-
```
41
-
42
-
3. The scrutinee of a match expression must be an `InfixExpr`. Previously the scrutinee could be followed by a typeascription `: T`, but this is no longer supported. So `x : T match { ... }` now has to be
43
-
written `(x: T) match { ... }`.
42
+
3. The scrutinee of a match expression must be an `InfixExpr`. Previously the scrutinee could be
43
+
followed by a typeascription `: T`, but this is no longer supported. So `x : T match { ... }`
0 commit comments