Skip to content

Commit

Permalink
Functional Python: 3rd version
Browse files Browse the repository at this point in the history
  • Loading branch information
tisnik committed Aug 7, 2023
1 parent e4c9a39 commit 27edf04
Showing 1 changed file with 77 additions and 1 deletion.
78 changes: 77 additions & 1 deletion docs/functional_python.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,26 +79,102 @@

### Higher order functions

- must exist by definition
- standard functions
- `map`
- `filter`
- `reduce` from functools

---

#### `map`

---

#### `filter`

---

#### `reduce`

---

### Lambdas

- anonymous functions
- not fully true in Python
- it's basically just an expression

---

#### Lambdas

---

### Closures

- must exist because:
- functions are first class citizens
- variables outside current block are accessible
- problems in Python
- not global, not local variables
- mutable access

---

#### Counter (incorrect)

---

#### Counter (correct)

---

### Generator expressions

- pretty nice way how to rewrite `map` and `filter`
- tuple comprehension
- list comprehension
- set comprehension
- dict comprehension

---

#### Tuple comprehension

---

#### List comprehension

---

#### Set comprehension

---

#### Dict comprehension

---

### Partial functions

---

### Caching
#### `partial` usage

---

### `partialmethod` usage

---

### Caching

- pure functions
- return values depends only on parameters
- it is a mapping, nothing else
- can be cached

---

#### `lru_cache` usage

0 comments on commit 27edf04

Please sign in to comment.