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

Skip to content

Commit bfe6647

Browse files
authored
Update README.md
1 parent 3077948 commit bfe6647

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ We can use the `inspect` module to know the arity of a function, see the example
7676
... return number_one * number_two
7777

7878
>>> assert len(signature(multiply).parameters) == 2
79+
>>>
7980
```
8081

8182
### Arity Distinctions
@@ -97,6 +98,7 @@ The __minimum arity__ is the smallest number of arguments the function expects t
9798

9899
>>> assert max_arity == 3
99100
>>> assert min_arity == 2
101+
>>>
100102
```
101103

102104
#### Fixed Arity and Variable Arity
@@ -111,6 +113,7 @@ A function has __fixed arity__ when you have to call it with the same number of
111113

112114
>>> def variable_arity(a: Any, b: Any = None) -> None: # we can call with 1 or 2 arguments
113115
... pass
116+
>>>
114117
```
115118

116119
#### Definitive Arity and Indefinite Arity
@@ -125,6 +128,7 @@ When a function can receive a finite number of arguments it has __definitive ari
125128

126129
>>> def indefinite_arity(*args: Any, **kwargs: Any) -> None: # we can call with how many arguments we want
127130
... pass
131+
>>>
128132
```
129133

130134
### Arguments vs Parameters
@@ -182,6 +186,7 @@ You can also use `functools.partial` or `returns.curry.partial` to partially app
182186
>>> assert partial(takes_three_arguments, 1, 2)(3) == 6
183187
>>> assert partial(takes_three_arguments, 1)(2, 3) == 6
184188
>>> assert partial(takes_three_arguments, 1, 2, 3)() == 6
189+
>>>
185190
```
186191

187192
The difference between `returns.curry.partial` and `functools.partial`
@@ -218,6 +223,7 @@ Each time the function is called it only accepts one argument and returns a func
218223
... return a + b + c
219224

220225
>>> assert takes_three_args(1)(2)(3) == 6
226+
>>>
221227
```
222228

223229
Some implementations of curried functions
@@ -227,6 +233,7 @@ can also take several of arguments instead of just a single argument:
227233
>>> assert takes_three_args(1, 2)(3) == 6
228234
>>> assert takes_three_args(1)(2, 3) == 6
229235
>>> assert takes_three_args(1, 2, 3) == 6
236+
>>>
230237
```
231238

232239
Let's see what type `takes_three_args` has to get a better understanding of its features:
@@ -257,6 +264,7 @@ For example, you can compose `abs` and `int` functions like so:
257264

258265
```python
259266
>>> assert abs(int('-1')) == 1
267+
>>>
260268
```
261269

262270
You can also create a third function
@@ -276,13 +284,15 @@ that will have an input of the first one and an output of the second one:
276284
... return lambda argument: second(first(argument))
277285

278286
>>> assert compose(int, abs)('-1') == 1
287+
>>>
279288
```
280289

281290
We already have this functions defined as `returns.functions.compose`!
282291

283292
```python
284293
>>> from returns.functions import compose
285294
>>> assert compose(bool, str)([]) == 'False'
295+
>>>
286296
```
287297

288298
__Further reading__
@@ -310,7 +320,8 @@ A function or expression is said to have a side effect if apart from returning a
310320
it interacts with (reads from or writes to) external mutable state:
311321

312322
```python
313-
print('This is a side effect!')
323+
>>> print('This is a side effect!')
324+
This is a side effect!
314325
```
315326

316327
Or:
@@ -331,6 +342,7 @@ This function is pure:
331342
```python
332343
>>> def add(first: int, second: int) -> int:
333344
... return first + second
345+
>>>
334346
```
335347

336348
As opposed to each of the following:
@@ -339,6 +351,7 @@ As opposed to each of the following:
339351
>>> def add_and_log(first: int, second: int) -> int:
340352
... print('Sum is:', first + second) # print is a side effect
341353
... return first + second
354+
>>>
342355
```
343356

344357

@@ -350,6 +363,7 @@ A function is idempotent if reapplying it to its result does not produce a diffe
350363
>>> assert sorted([2, 1]) == [1, 2]
351364
>>> assert sorted(sorted([2, 1])) == [1, 2]
352365
>>> assert sorted(sorted(sorted([2, 1]))) == [1, 2]
366+
>>>
353367
```
354368

355369
## Point-Free Style (TODO)

0 commit comments

Comments
 (0)
0