Optics Journeys
"For the things we have to learn before we can do them, we learn by doing them." — Aristotle, Nicomachean Ethics
Six journeys covering the full optics surface, from first-principles Lens and Prism through the Focus DSL to batching, coupled updates, and the generated DTO boundary. Work them in order: each builds on concepts introduced earlier. Reading the Optics chapter instead? Practising alongside the Optics chapter pairs each of its first pages with the tutorials that practise it.
The .focus().attributes().at(key) token in One Line, Six Layers is the optic layer; these journeys teach the pieces that compose into that one fluent path. The reference material lives in the Optics chapter and, for the final journey, the Mapping at the Boundary chapter.
- Lens & Prism – The foundations: focusing on one field of a record, one variant of a sealed type, and composing the two. Everything later builds on these exercises.
- Traversals & Practice – Zero-or-more focus: bulk operations over collections, composition with lenses and prisms, and the real-world shapes they unlock.
- Fluent & Free DSL – The ergonomic layer for validation-aware updates, advanced prism patterns, and optics as programs-as-data with multiple interpreters.
- Focus DSL – Type-safe path navigation with automatic type widening through optional values and collections; the way most day-to-day optics code is written.
- Batching & Coupled Updates – What happens when paths meet the outside world and each other: one batched call per traversal instead of N, plans you can inspect and bound, and atomic updates for fields that share an invariant.
- Boundary Mapping – The hands-on lane for the mapping chapter: hand-written multi-edits, the
ValidatedPrismleaf, the whole DTO boundary generated and law-checked, and the edge cases a real request brings.
Chapter Contents
- Lens & Prism: Lens basics, composition, Prism, Affine
- Traversals & Practice: Traversals, composition, real-world applications
- Fluent & Free DSL: Fluent API, advanced Prisms, Free Monad DSL
- Focus DSL: Type-safe path navigation, container widening
- Batching & Coupled Updates: Request batching, guardrails, coupled lenses
- Boundary Mapping: Multi-edit, ValidatedPrism, generated record mapping, boundary edge cases
Practising alongside the Optics chapter
The Optics chapter's first pages each reach a "You can ship now" tip. These tutorials practise what each page taught, so you can work one after reading its page rather than waiting for a whole journey. Each still assumes the tutorials its own header names: the Focus DSL ones, for instance, assume Tutorials 01-06.
At a glance:
| Journey | Exercises |
|---|---|
| Lens & Prism | 33 |
| Traversals & Practice | 28 |
| Fluent & Free DSL | 22 |
| Focus DSL | 90 |
| Batching & Coupled Updates | 13 |
| Boundary Mapping | 24 |
Previous: Effect Handlers Next: Lens & Prism