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#

#FileTopic
0101-effect-thunk-result.mdEffect, Thunk[T], Result[T].
0202-closures-ioc.mdClosures as the primitive of inversion of control.
0303-lazy-evaluation.mdLaziness everywhere: ChainRunner, validate.execute, Watcher callback, lazy prefixes.
0404-fold-reduce.mdreduce (fold left) in chain_actions.
0505-declarative.mdDeclarative programming: a scenario describes, doesn’t execute.
0606-pep-695-generics.mdPEP 695 generics, TypeVar bound, type X[T] = ....
0707-discriminated-unions-typeguards.mdDiscriminated 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,