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

Skip to content

Commit 71a949a

Browse files
authored
Update README.md
1 parent fd00718 commit 71a949a

File tree

1 file changed

+36
-5
lines changed

1 file changed

+36
-5
lines changed

README.md

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ __Table of Contents__
2222
* [Currying](#currying)
2323
* [Function Composition](#function-composition)
2424
* [Continuation (TODO)](#continuation-todo)
25-
* [Point-Free Style (TODO)](#point-free-style-todo)
25+
* [Point-Free Style](#point-free-style)
2626
* [Predicate](#predicate)
2727
* [Contracts (TODO)](#contracts-todo)
2828
* [Category (TODO)](#category-todo)
@@ -429,15 +429,46 @@ Continuations are often seen in asynchronous programming when the program needs
429429
```
430430

431431

432-
## Point-Free Style (TODO)
432+
## Point-Free Style
433433

434-
Writing functions where the definition does not explicitly identify the arguments used. This style usually requires [currying](#currying) or other [Higher-Order functions](#higher-order-functions-hof). A.K.A Tacit programming.
434+
Point-Free is a style of writting code without using any intermediate variables.
435+
436+
Basically, you will end up with long chains of direct function calls.
437+
This style usually requires [currying](#currying) or other [Higher-Order functions](#higher-order-functions-hof).
438+
This technique is also sometimes called "Tacit programming".
439+
440+
The most common example of Point-Free programming style is Unix with pipes:
441+
442+
```bash
443+
ps aux | grep [k]de | gawk '{ print $2 }'
444+
```
445+
446+
It also works for Python, let's say you have this function composition:
435447

436448
```python
437-
# TODO
449+
>>> str(bool(abs(-1)))
450+
'True'
438451
```
439452

440-
Points-free function definitions look just like normal assignments without `def` or `lambda`.
453+
It might be problematic method methods on the first sight, because you need an instance to call a method on.
454+
But, you can always use HOF to fix that and compose normally:
455+
456+
```python
457+
>>> from returns.pipeline import flow
458+
>>> from returns.pointfree import map_
459+
>>> from returns.result import Success
460+
461+
>>> assert flow(
462+
... Success(-2)
463+
... map_(abs),
464+
... map_(range),
465+
... map_(list),
466+
... ) == Success([0, 1])
467+
>>>
468+
```
469+
470+
__Further reading:__
471+
* [Pointfree docs](https://returns.readthedocs.io/en/latest/pages/pointfree.html)
441472

442473

443474
## Predicate

0 commit comments

Comments
 (0)
0