Skip to content

fix type err, improve readability of patmat doc #16132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions docs/_docs/reference/changed-features/pattern-matching.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,29 @@ Scala 3 supports a superset of Scala 2 [extractors](https://www.scala-lang.org/f
Extractors are objects that expose a method `unapply` or `unapplySeq`:

```scala
def unapply[A](x: T)(implicit x: B): U
def unapplySeq[A](x: T)(implicit x: B): U
def unapply[A](a: A): U
def unapplySeq[A](a: A): U
```

Extractors that expose the method `unapply` are called fixed-arity extractors, which
work with patterns of fixed arity. Extractors that expose the method `unapplySeq` are
called variadic extractors, which enables variadic patterns.

The type `A` corresponds to the type of the matched value. The result type `U` determines the type of extractor as explained in subsequent sections.

It is also possible to have using-parameters if needed in the implementation of the extractor body:

```scala
def unapply[A](a: A)(using b: B): U
def unapplySeq[A](a: A)(using b: B): U
```

### Fixed-Arity Extractors

Fixed-arity extractors expose the following signature:

```scala
def unapply[A](x: T)(implicit x: B): U
def unapply[A](a: A): U
```

The type `U` conforms to one of the following matches:
Expand Down Expand Up @@ -63,7 +72,7 @@ A usage of a fixed-arity extractor is irrefutable if one of the following condit
Variadic extractors expose the following signature:

```scala
def unapplySeq[A](x: T)(implicit x: B): U
def unapplySeq[A](a: A): U
```

The type `U` conforms to one of the following matches:
Expand Down