Skip to content

Commit 68f5873

Browse files
authored
Update higher-order-functions.md
1 parent 382a5cc commit 68f5873

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

_tour/higher-order-functions.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ In a pure Object Oriented world a good practice is to avoid exposing methods par
2121
One of the most common examples is the higher-order
2222
function `map` which is available for collections in Scala.
2323

24-
{% tabs map_example_1 %}
24+
{% tabs map_example_1 class=tabs-scala-version %}
2525

2626
{% tab 'Scala 2' for=map_example_1 %}
2727
```scala mdoc
@@ -47,7 +47,7 @@ list of salaries.
4747
To shrink the code, we could make the function anonymous and pass it directly as
4848
an argument to map:
4949

50-
{% tabs map_example_2 %}
50+
{% tabs map_example_2 class=tabs-scala-version %}
5151

5252
{% tab 'Scala 2' for=map_example_2 %}
5353
```scala:nest
@@ -68,7 +68,7 @@ val newSalaries = salaries.map(x => x * 2) // List(40000, 140000, 80000)
6868
Notice how `x` is not declared as an Int in the above example. That's because the
6969
compiler can infer the type based on the type of function map expects (see [Currying](/tour/multiple-parameter-lists.html)). An even more idiomatic way to write the same piece of code would be:
7070

71-
{% tabs map_example_3 %}
71+
{% tabs map_example_3 class=tabs-scala-version %}
7272

7373
{% tab 'Scala 2' for=map_example_3 %}
7474
```scala mdoc:nest
@@ -95,7 +95,7 @@ the previous example).
9595
It is also possible to pass methods as arguments to higher-order functions because
9696
the Scala compiler will coerce the method into a function.
9797

98-
{% tabs Coercing_methods_into_functions %}
98+
{% tabs Coercing_methods_into_functions class=tabs-scala-version %}
9999

100100
{% tab 'Scala 2' for=Coercing_methods_into_functions %}
101101
```scala mdoc
@@ -127,7 +127,7 @@ Here the method `convertCtoF` is passed to the higher order function `map`. This
127127
One reason to use higher-order functions is to reduce redundant code. Let's say you wanted some methods that could raise someone's salaries by various factors. Without creating a higher-order function,
128128
it might look something like this:
129129

130-
{% tabs Functions_that_accept_functions_1 %}
130+
{% tabs Functions_that_accept_functions_1 class=tabs-scala-version %}
131131

132132
{% tab 'Scala 2' for=Functions_that_accept_functions_1 %}
133133
```scala mdoc
@@ -165,7 +165,7 @@ object SalaryRaiser:
165165
Notice how each of the three methods vary only by the multiplication factor. To simplify,
166166
you can extract the repeated code into a higher-order function like so:
167167

168-
{% tabs Functions_that_accept_functions_2 %}
168+
{% tabs Functions_that_accept_functions_2 class=tabs-scala-version %}
169169

170170
{% tab 'Scala 2' for=Functions_that_accept_functions_2 %}
171171
```scala mdoc:nest
@@ -216,7 +216,7 @@ Methods and functions usually express behaviours or data transformations, theref
216216
There are certain cases where you want to generate a function. Here's an example
217217
of a method that returns a function.
218218

219-
{% tabs Functions_that_return_functions %}
219+
{% tabs Functions_that_return_functions class=tabs-scala-version %}
220220

221221
{% tab 'Scala 2' for=Functions_that_return_functions %}
222222
```scala mdoc

0 commit comments

Comments
 (0)