Skip to content
Merged
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
10 changes: 9 additions & 1 deletion _overviews/scala3-book/types-intersection.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ num: 50
previous-page: types-generics
next-page: types-union
---

<span class="tag tag-inline">Scala 3 only</span>

Used on types, the `&` operator creates a so called _intersection type_.
The type `A & B` represents values that are **both** of the type `A` and of the type `B` at the same time.
For instance, the following example uses the intersection type `Resettable & Growable[String]`:

{% tabs intersection-reset-grow %}

{% tab 'Scala 3 Only' %}

```scala
trait Resettable:
def reset(): Unit
Expand All @@ -25,6 +29,10 @@ def f(x: Resettable & Growable[String]): Unit =
x.add("first")
```

{% endtab %}

{% endtabs %}

In the method `f` in this example, the parameter `x` is required to be *both* a `Resettable` and a `Growable[String]`.

The _members_ of an intersection type `A & B` are all the members of `A` and all the members of `B`.
Expand Down