@@ -17,8 +17,8 @@ __Table of Contents__
17
17
* [ Auto Currying (TODO)] ( #auto-currying-todo )
18
18
* [ Function Composition (TODO)] ( #function-composition-todo )
19
19
* [ Continuation (TODO)] ( #continuation-todo )
20
+ * [ Side effects] ( #side-effects-todo )
20
21
* [ Purity] ( #purity-todo )
21
- * [ Side effects (TODO)] ( #side-effects-todo )
22
22
* [ Idempotent (TODO)] ( #idempotent-todo )
23
23
* [ Point-Free Style (TODO)] ( #point-free-style-todo )
24
24
* [ Predicate (TODO)] ( #predicate-todo )
@@ -165,7 +165,27 @@ Continuations are often seen in asynchronous programming when the program needs
165
165
# TODO
166
166
```
167
167
168
- ## Purity (TODO)
168
+ ## Side effects
169
+
170
+ A function or expression is said to have a side effect if apart from returning a value,
171
+ it interacts with (reads from or writes to) external mutable state:
172
+
173
+ ``` python
174
+ print (' This is a side effect!' )
175
+ ```
176
+
177
+ Or:
178
+
179
+ ``` python
180
+ result_sums = []
181
+
182
+ def add (first : int , second : int ) -> int :
183
+ result_sum = first + second
184
+ result_sums.append(result_sum) # this is a side effect
185
+ return result_sum
186
+ ```
187
+
188
+ ## Purity
169
189
170
190
A function is pure if the return value is only determined by its
171
191
input values, and does not produce any side effects.
@@ -185,20 +205,6 @@ def add_and_log(first: int, second: int) -> int:
185
205
return first + second
186
206
```
187
207
188
- ## Side effects (TODO)
189
-
190
- A function or expression is said to have a side effect if apart from returning a value,
191
- it interacts with (reads from or writes to) external mutable state.
192
-
193
- ``` python
194
- result_sums = []
195
-
196
- def add (first : int , second : int ) -> int :
197
- result_sum = first + second
198
- result_sums.append(result_sum) # this is a side effect
199
- return result_sum
200
- ```
201
-
202
208
## Idempotent (TODO)
203
209
204
210
A function is idempotent if reapplying it to its result does not produce a different result.
0 commit comments