Skip to content

Commit bb8f701

Browse files
committed
correct 2&3 and 3 only tabs.
1 parent c6b1220 commit bb8f701

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

_overviews/scala3-book/taste-collections.md

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ These examples show different ways to create a populated `List`:
1919

2020
{% tabs collection_1 %}
2121
{% tab 'Scala 2 and 3' for=collection_1 %}
22+
2223
```scala
2324
val a = List(1, 2, 3) // a: List[Int] = List(1, 2, 3)
2425

@@ -29,6 +30,7 @@ val e = (1 until 5).toList // e: List[Int] = List(1, 2, 3, 4)
2930
val f = List.range(1, 5) // f: List[Int] = List(1, 2, 3, 4)
3031
val g = List.range(1, 10, 3) // g: List[Int] = List(1, 4, 7)
3132
```
33+
3234
{% endtab %}
3335
{% endtabs %}
3436

@@ -38,8 +40,9 @@ Once you have a populated list, the following examples show some of the methods
3840
Notice that these are all functional methods, meaning that they don’t mutate the collection they’re called on, but instead return a new collection with the updated elements.
3941
The result that’s returned by each expression is shown in the comment on each line:
4042

41-
{% tabs collection_2 class=tabs-scala-version %}
43+
{% tabs collection_2 %}
4244
{% tab 'Scala 2 and 3' for=collection_2 %}
45+
4346
```scala
4447
// a sample list
4548
val a = List(10, 20, 30, 40, 10) // List(10, 20, 30, 40, 10)
@@ -61,19 +64,22 @@ val nums = List("one", "two")
6164
nums.map(_.toUpperCase) // List("ONE", "TWO")
6265
nums.flatMap(_.toUpperCase) // List('O', 'N', 'E', 'T', 'W', 'O')
6366
```
67+
6468
{% endtab %}
6569
{% endtabs %}
6670

6771
These examples show how the “foldLeft” and “reduceLeft” methods are used to sum the values in a sequence of integers:
6872

69-
{% tabs collection_3 class=tabs-scala-version %}
73+
{% tabs collection_3 %}
7074
{% tab 'Scala 2 and 3' for=collection_3 %}
75+
7176
```scala
7277
val firstTen = (1 to 10).toList // List(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
7378

7479
firstTen.reduceLeft(_ + _) // 55
7580
firstTen.foldLeft(100)(_ + _) // 155 (100 is a “seed” value)
7681
```
82+
7783
{% endtab %}
7884
{% endtabs %}
7985

@@ -84,40 +90,47 @@ There are many more methods available to Scala collections classes, and they’r
8490
The Scala _tuple_ is a type that lets you easily put a collection of different types in the same container.
8591
For example, given this `Person` case class:
8692

87-
{% tabs collection_4 class=tabs-scala-version %}
93+
{% tabs collection_4 %}
8894
{% tab 'Scala 2 and 3' for=collection_4 %}
95+
8996
```scala
9097
case class Person(name: String)
9198
```
99+
92100
{% endtab %}
93101
{% endtabs %}
94102

95103
This is how you create a tuple that contains an `Int`, a `String`, and a custom `Person` value:
96104

97-
{% tabs collection_5 class=tabs-scala-version %}
105+
{% tabs collection_5 %}
98106
{% tab 'Scala 2 and 3' for=collection_5 %}
107+
99108
```scala
100109
val t = (11, "eleven", Person("Eleven"))
101110
```
111+
102112
{% endtab %}
103113
{% endtabs %}
104114

105115
Once you have a tuple, you can access its values by binding them to variables, or access them by number:
106116

107-
{% tabs collection_6 class=tabs-scala-version %}
117+
{% tabs collection_6 %}
108118
{% tab 'Scala 2 and 3' for=collection_6 %}
119+
109120
```scala
110121
t(0) // 11
111122
t(1) // "eleven"
112123
t(2) // Person("Eleven")
113124
```
125+
114126
{% endtab %}
115127
{% endtabs %}
116128

117129
You can also use this _extractor_ approach to assign the tuple fields to variable names:
118130

119-
{% tabs collection_7 class=tabs-scala-version %}
131+
{% tabs collection_7 %}
120132
{% tab 'Scala 2 and 3' for=collection_7 %}
133+
121134
```scala
122135
val (num, str, person) = t
123136

@@ -126,6 +139,7 @@ val (num, str, person) = t
126139
// val str: String = eleven
127140
// val person: Person = Person(Eleven)
128141
```
142+
129143
{% endtab %}
130144
{% endtabs %}
131145

0 commit comments

Comments
 (0)