@@ -19,7 +19,7 @@ __Table of Contents__
19
19
* [ Continuation (TODO)] ( #continuation-todo )
20
20
* [ Side effects] ( #side-effects )
21
21
* [ Purity] ( #purity )
22
- * [ Idempotent (TODO) ] ( #idempotent-todo )
22
+ * [ Idempotent] ( #idempotent )
23
23
* [ Point-Free Style (TODO)] ( #point-free-style-todo )
24
24
* [ Predicate (TODO)] ( #predicate-todo )
25
25
* [ Contracts (TODO)] ( #contracts-todo )
@@ -189,24 +189,26 @@ input values, and does not produce any side effects.
189
189
This function is pure:
190
190
191
191
``` python
192
- def add (first : int , second : int ) -> int :
193
- return first + second
192
+ >> > def add (first : int , second : int ) -> int :
193
+ ... return first + second
194
194
```
195
195
196
196
As opposed to each of the following:
197
197
198
198
``` python
199
- def add_and_log (first : int , second : int ) -> int :
200
- print (' Sum is:' , first + second) # print is a side effect
201
- return first + second
199
+ >> > def add_and_log (first : int , second : int ) -> int :
200
+ ... print (' Sum is:' , first + second) # print is a side effect
201
+ ... return first + second
202
202
```
203
203
204
- ## Idempotent (TODO)
204
+ ## Idempotent
205
205
206
- A function is idempotent if reapplying it to its result does not produce a different result.
206
+ A function is idempotent if reapplying it to its result does not produce a different result:
207
207
208
208
``` python
209
- # TODO
209
+ >> > assert sorted ([2 , 1 ]) == [1 , 2 ]
210
+ >> > assert sorted (sorted ([2 , 1 ])) == [1 , 2 ]
211
+ >> > assert sorted (sorted (sorted ([2 , 1 ]))) == [1 , 2 ]
210
212
```
211
213
212
214
## Point-Free Style (TODO)
0 commit comments