You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _tour/higher-order-functions.md
+7-7Lines changed: 7 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -21,7 +21,7 @@ In a pure Object Oriented world a good practice is to avoid exposing methods par
21
21
One of the most common examples is the higher-order
22
22
function `map` which is available for collections in Scala.
23
23
24
-
{% tabs map_example_1 %}
24
+
{% tabs map_example_1 class=tabs-scala-version %}
25
25
26
26
{% tab 'Scala 2' for=map_example_1 %}
27
27
```scala mdoc
@@ -47,7 +47,7 @@ list of salaries.
47
47
To shrink the code, we could make the function anonymous and pass it directly as
48
48
an argument to map:
49
49
50
-
{% tabs map_example_2 %}
50
+
{% tabs map_example_2 class=tabs-scala-version %}
51
51
52
52
{% tab 'Scala 2' for=map_example_2 %}
53
53
```scala:nest
@@ -68,7 +68,7 @@ val newSalaries = salaries.map(x => x * 2) // List(40000, 140000, 80000)
68
68
Notice how `x` is not declared as an Int in the above example. That's because the
69
69
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:
70
70
71
-
{% tabs map_example_3 %}
71
+
{% tabs map_example_3 class=tabs-scala-version %}
72
72
73
73
{% tab 'Scala 2' for=map_example_3 %}
74
74
```scala mdoc:nest
@@ -95,7 +95,7 @@ the previous example).
95
95
It is also possible to pass methods as arguments to higher-order functions because
96
96
the Scala compiler will coerce the method into a function.
@@ -127,7 +127,7 @@ Here the method `convertCtoF` is passed to the higher order function `map`. This
127
127
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,
0 commit comments