Chapter 03 — Functional programming with Ocarina#
How Ocarina applies functional programming and why. This chapter is more transversal than the others — it revisits the framework’s mechanics from an FP angle.
Outline#
| # | File | Topic |
|---|---|---|
| 01 | 01-effect-thunk-result.md | Effect, Thunk[T], Result[T]. |
| 02 | 02-closures-ioc.md | Closures as the primitive of inversion of control. |
| 03 | 03-lazy-evaluation.md | Laziness everywhere: ChainRunner, validate.execute, Watcher callback, lazy prefixes. |
| 04 | 04-fold-reduce.md | reduce (fold left) in chain_actions. |
| 05 | 05-declarative.md | Declarative programming: a scenario describes, doesn’t execute. |
| 06 | 06-pep-695-generics.md | PEP 695 generics, TypeVar bound, type X[T] = .... |
| 07 | 07-discriminated-unions-typeguards.md | Discriminated unions + TypeGuard + @final = “sealed” unions. |
Why a dedicated chapter#
Ocarina’s code is small but embodies a serious number of FP patterns. This chapter names them, justifies them, and points to where they live in the code.
Holy Book quote (chapter “First feedbacks”):
Twisting Ocarina’s ROP (Railway Oriented Programming) implementation until it lost all meaning, since they didn’t even know what ROP is, … Forcing their clueless take on lazy evaluation and IoC down my throat like it’s gospel, … “Explaining” imperative vs. declarative programming to me while spewing complete nonsense, …