8000 Update README.md · bitnom/functional-jargon-python@42b54c4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 42b54c4

Browse files
authored
Update README.md
1 parent b73b3bd commit 42b54c4

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

README.md

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ __Table of Contents__
1717
* [Auto Currying (TODO)](#auto-currying-todo)
1818
* [Function Composition (TODO)](#function-composition-todo)
1919
* [Continuation (TODO)](#continuation-todo)
20+
* [Side effects](#side-effects-todo)
2021
* [Purity](#purity-todo)
21-
* [Side effects (TODO)](#side-effects-todo)
2222
* [Idempotent (TODO)](#idempotent-todo)
2323
* [Point-Free Style (TODO)](#point-free-style-todo)
2424
* [Predicate (TODO)](#predicate-todo)
@@ -165,7 +165,27 @@ Continuations are often seen in asynchronous programming when the program needs
165165
# TODO
166166
```
167167

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
169189

170190
A function is pure if the return value is only determined by its
171191
input values, and does not produce any side effects.
@@ -185,20 +205,6 @@ def add_and_log(first: int, second: int) -> int:
185205
return first + second
186206
```
187207

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-
202208
## Idempotent (TODO)
203209

204210
A function is idempotent if reapplying it to its result does not produce a different result.

0 commit comments

Comments
 (0)
0