Skip to content

Commit b35bdb0

Browse files
authored
Add code tabs for _overviews/scala3-book/types-intersection.md (#2653)
1 parent 98bd195 commit b35bdb0

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Diff for: _overviews/scala3-book/types-intersection.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@ num: 50
77
previous-page: types-generics
88
next-page: types-union
99
---
10-
10+
<span class="tag tag-inline">Scala 3 only</span>
1111

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

16+
{% tabs intersection-reset-grow %}
17+
18+
{% tab 'Scala 3 Only' %}
19+
1620
```scala
1721
trait Resettable:
1822
def reset(): Unit
@@ -25,6 +29,10 @@ def f(x: Resettable & Growable[String]): Unit =
2529
x.add("first")
2630
```
2731

32+
{% endtab %}
33+
34+
{% endtabs %}
35+
2836
In the method `f` in this example, the parameter `x` is required to be *both* a `Resettable` and a `Growable[String]`.
2937

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

0 commit comments

Comments
 (0)