Skip to content

Commit 88f413c

Browse files
Ignacio Lucerojvican
Ignacio Lucero
authored andcommitted
Fix redundant sentences and one example. (#1026)
1 parent cb775b3 commit 88f413c

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

Diff for: _tour/higher-order-functions.md

+3-7
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ val salaries = Seq(20000, 70000, 40000)
3636
val newSalaries = salaries.map(x => x * 2) // List(40000, 140000, 80000)
3737
```
3838
Notice how `x` is not declared as an Int in the above example. That's because the
39-
compiler can infer the type based on the type of function map expects. An even more idiomatic way to write the same piece of code would be
40-
41-
Here is another example:
39+
compiler can infer the type based on the type of function map expects. An even more idiomatic way to write the same piece of code would be:
4240

4341
```tut
4442
val salaries = Seq(20000, 70000, 40000)
@@ -60,7 +58,7 @@ case class WeeklyWeatherForecast(temperatures: Seq[Double]) {
6058
def forecastInFahrenheit: Seq[Double] = temperatures.map(convertCtoF) // <-- passing the method convertCtoF
6159
}
6260
```
63-
Here the method `convertCtoF` is passed to forecastInFahrenheit This is possible because the compiler coerces `convertCtoF` to the function `x => convertCtoF(x)` (note: `x` will
61+
Here the method `convertCtoF` is passed to `forecastInFahrenheit`. This is possible because the compiler coerces `convertCtoF` to the function `x => convertCtoF(x)` (note: `x` will
6462
be a generated name which is guaranteed to be unique within its scope).
6563

6664
## Functions that accept functions
@@ -81,8 +79,6 @@ object SalaryRaiser {
8179
}
8280
```
8381

84-
Execution yields the output:
85-
8682
Notice how each of the three methods vary only by the multiplication factor. To simplify,
8783
you can extract the repeated code into a higher-order function like so:
8884

@@ -126,4 +122,4 @@ val url = getURL(endpoint, query) // "https://www.example.com/users?id=1": Strin
126122

127123
Notice the return type of urlBuilder `(String, String) => String`. This means that
128124
the returned anonymous function takes two Strings and returns a String. In this case,
129-
the returned anonymous function is `(endpoint: String, query: String) => s"$schema$domainName/$endpoint?$query"`.
125+
the returned anonymous function is `(endpoint: String, query: String) => s"https://www.example.com/$endpoint?$query"`.

0 commit comments

Comments
 (0)