Skip to content

Commit d653012

Browse files
committed
Add reference doc page
1 parent 1a2cf42 commit d653012

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
layout: doc-page
3+
title: Match Expressions
4+
---
5+
6+
The syntactical precedence of match expressions has been changed.
7+
`match` is still a keyword, but it is used like an alphabetical operator. This has several consequences:
8+
9+
1. `match` expressions can be chained:
10+
11+
```scala
12+
xs match {
13+
case Nil => "empty"
14+
case x :: xs1 => "nonempty"
15+
} match {
16+
case "empty" => 0
17+
case "nonempty" => 1
18+
}
19+
20+
2. `match` may follow a period:
21+
22+
```scala
23+
if xsDefined
24+
&& xs.match {
25+
case Nil => false
26+
case _ => true
27+
}
28+
then "nonempty"
29+
else "empty"
30+
31+
3. The scrutinee of a match expression must be an `InfixExpr`. Previously the scrutinee could be followed by a type ascription `: T`, but this is no longer supported. So `x : T match { ... }` now has to be
32+
written `(x: T) match { ... }`.
33+
34+
## Syntax
35+
36+
The new syntax of match expressions is as follows.
37+
```
38+
InfixExpr ::= ...
39+
| InfixExpr MatchClause
40+
SimpleExpr ::= ...
41+
| SimpleExpr ‘.’ MatchClause
42+
MatchClause ::= ‘match’ ‘{’ CaseClauses ‘}’
43+
```

docs/sidebar.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ sidebar:
127127
url: docs/reference/changed-features/implicit-conversions.html
128128
- title: Overload Resolution
129129
url: docs/reference/changed-features/overload-resolution.html
130+
- title: Match Expressions
131+
url: docs/reference/changed-features/match-syntax.html
130132
- title: Vararg Patterns
131133
url: docs/reference/changed-features/vararg-patterns.html
132134
- title: Pattern Bindings

0 commit comments

Comments
 (0)