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.

Where This Fits in the Bigger Picture

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.

In This 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 thirty 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 ValidatedPrism leaf, and the whole DTO boundary generated and law-checked.

Chapter Contents

  1. Lens & Prism - Lens basics, composition, Prism, Affine
  2. Traversals & Practice - Traversals, composition, real-world applications
  3. Fluent & Free DSL - Fluent API, advanced Prisms, Free Monad DSL
  4. Focus DSL - Type-safe path navigation, container widening
  5. Batching & Coupled Updates - Request batching, guardrails, coupled lenses
  6. Boundary Mapping - Multi-edit, ValidatedPrism, generated record mapping

At a glance:

JourneyDurationExercises
Lens & Prism~40 min30
Traversals & Practice~40 min27
Fluent & Free DSL~35 min22
Focus DSL~35 min29
Batching & Coupled Updates~40 min13
Boundary Mapping~35 min13

Next: Lens & Prism