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
@@ -168,24 +168,35 @@ Continuations are often seen in asynchronous programming when the program needs
168
168
## Purity (TODO)
169
169
170
170
A function is pure if the return value is only determined by its
171
-
input values, and does not produce side effects.
171
+
input values, and does not produce any side effects.
172
+
173
+
This function is pure:
172
174
173
175
```python
174
-
#TODO
176
+
defadd(first: int, second: int) -> int:
177
+
return first + second
175
178
```
176
179
177
180
As opposed to each of the following:
178
181
179
182
```python
180
-
#TODO
183
+
defadd_and_log(first: int, second: int) -> int:
184
+
print('Sum is:', first + second) # print is a side effect
185
+
return first + second
181
186
```
182
187
183
188
## Side effects (TODO)
184
189
185
-
A function or expression is said to have a side effect if apart from returning a value, it interacts with (reads from or writes to) external mutable state.
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.
186
192
187
193
```python
188
-
#TODO
194
+
result_sums = []
195
+
196
+
defadd(first: int, second: int) -> int:
197
+
result_sum = first + second
198
+
result_sums.append(result_sum) # this is a side effect
0 commit comments