Skip to content

Commit b3bd621

Browse files
authored
Update higher-order-functions.md
enhanced doc on methods that take fns as args
1 parent 64e5b04 commit b3bd621

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

_tour/higher-order-functions.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ case class WeeklyWeatherForecast(temperatures: Seq[Double]) {
6060
```
6161
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
6262
be a generated name which is guaranteed to be unique within its scope).
63+
64+
In a pure Object Oriented world a good practice is to avoid exposing methods that are parameterized with functions that might escape the internal state of the objects. Leaking internal state might break the invariants of the object itself.
6365

6466
## Functions that accept functions
6567
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

Comments
 (0)