Skip to content

Commit 475b83e

Browse files
committed
Tweak wording in tour of extractors
1 parent 117d473 commit 475b83e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

_tour/extractor-objects.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ customer1ID match {
3737

3838
The `apply` method creates a `CustomerID` string from a `name`. The `unapply` does the inverse to get the `name` back. When we call `CustomerID("Sukyoung")`, this is shorthand syntax for calling `CustomerID.apply("Sukyoung")`. When we call `case CustomerID(name) => println(name)`, we're calling the unapply method.
3939

40-
The unapply method can also be used to assign a value.
40+
Since a value definition can use a pattern to introduce a new variable, an extractor can be used to initialize the variable, where the unapply method supplies the value.
4141

4242
```tut
4343
val customer2ID = CustomerID("Nico")
@@ -63,4 +63,4 @@ The return type of an `unapply` should be chosen as follows:
6363
* If it returns a single sub-value of type T, return an `Option[T]`.
6464
* If you want to return several sub-values `T1,...,Tn`, group them in an optional tuple `Option[(T1,...,Tn)]`.
6565

66-
Sometimes, the number of sub-values isn't fixed and we would like to return a sequence. For this reason, you can also define patterns through `unapplySeq` which returns `Option[Seq[T]]` This mechanism is used for instance in pattern `case List(x1, ..., xn)`.
66+
Sometimes, the number of values to extract isn't fixed and we would like to return an arbitrary number of values, depending on the input. For this use case, you can define extractors with an `unapplySeq` method which returns an `Option[Seq[T]]`. Common examples of these patterns include deconstructing a `List` using `case List(x, y, z) =>` and decomposing a `String` using a regular expression `Regex`, such as `case r(name, remainingFields @ _*) =>`.

0 commit comments

Comments
 (0)