A small project to practice functional programming patterns in modern Python:
lambdas, higher-order functions, closures, functools, and decorators.
The focus is not “clever code”, but clear, testable, explainable design using function composition and controlled side effects.
- Use functions as first-class objects (pass/return functions)
- Build closures that preserve state safely
- Apply
functoolsutilities to simplify patterns - Write decorators that keep metadata with
functools.wraps - Keep code clean, typed, and lint-friendly (
flake8)
-
ex0 —
lambda_spells.py
Lambdas +sorted,filter, basic transformations and stats. -
ex1 —
higher_magic.py
Higher-order functions: combine, amplify, conditionally apply and sequence spells. -
ex2 —
scope_mysteries.py
Closures, lexical scope, andnonlocalstate. -
ex3 —
functools_artifacts.py
reduce,partial,lru_cache, andsingledispatch. -
ex4 —
decorator_mastery.py
Decorators withwraps, parametrized decorators, retry logic, and static methods.
From the repository root:
python3 ex0/lambda_spells.py
python3 ex1/higher_magic.py
python3 ex2/scope_mysteries.py
python3 ex3/functools_artifacts.py
python3 ex4/decorator_mastery.py