Skip to content

Commit 2e29269

Browse files
authored
fix typos
1 parent 22ef474 commit 2e29269

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

_overviews/scala3-book/fp-pure-functions.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Conversely, the following functions are _impure_ because they violate the defini
5757

5858
Impure functions often do one or more of these things:
5959

60-
- Read from hidden mutable state, i.e., they access non-constant variables and data not explicitly passed into the function as input parameters.
60+
- Read from hidden mutable state, i.e., they access non-constant data that was not explicitly passed into the function as input parameters
6161
- Write to hidden state
6262
- Mutate the parameters they’re given, or mutate hidden variables, such as fields in their containing class
6363
- Perform some sort of I/O with the outside world
@@ -98,17 +98,16 @@ def double(i: Int): Int = i * 2
9898

9999
{% endtabs %}
100100

101-
The next example is bit more tricky. Here, i is not passed as a parameter, but instead referenced directly from the function body.
102-
This works in Scala because functions act as closure - they can capture the state around them. As long as that state is *immutable*, the function is still considered pure.
103-
In this case, the function always returns `6` and each call could be safely replaced with its result.
104-
This concept of closures and "fixing values" is an important tool in functional programming that you will encounter often as you go forward.
101+
The next example is bit more tricky. Here, `i` is not passed as a parameter, but instead referenced directly from the outside.
102+
This works in Scala because functions act as closures - they can capture the state around them. As long as that state is *immutable*, such a closure is still considered pure.
103+
In this case, the function always returns `6` and each call can be safely replaced with its result.
105104

106105
{% tabs fp-pure-function-closure %}
107106

108107
{% tab 'Scala 2 and 3' %}
109108
```scala
110109
val i = 3
111-
def double(i: Int): Int = i * 2
110+
def double(): Int = i * 2
112111
```
113112
{% endtab %}
114113

@@ -145,7 +144,7 @@ If you understand that code, you’ll see that it meets the pure function defini
145144

146145
The first key point of this section is the definition of a pure function:
147146

148-
> A _pure function_ is a function that depends only on its declared inputs and its implementation to produce its output.
147+
> A _pure function_ is a function that depends only on its declared inputs, captured constants, and its implementation to produce its output.
149148
> It only computes its output and does not depend on or modify the outside world.
150149
151150
A second key point is that every real-world application interacts with the outside world.

0 commit comments

Comments
 (0)