Lenses, prisms, and traversals are composable abstractions that solve Java's immutability gap by treating access paths as first-class values. Lenses focus on exactly one value in product types, prisms handle optional variants in sum types, and traversals operate on zero or more values in collections. Using Higher-Kinded-J's annotation-driven generation, these optics compose to create powerful paths for reading and updating deeply nested immutable structures without manual reconstruction. The article demonstrates practical patterns including lens composition, type-safe downcasting with prisms, filtered traversals, and previews effect-polymorphic operations and the Focus DSL.
Table of contents
Setting Up Higher-Kinded-JArticle CodeLenses: The FoundationPrisms: Sum Type AccessTraversals: Bulk OperationsComposition PatternsEffect-Polymorphic Operations: A PreviewIntroducing the Expression LanguageSummaryFurther ReadingSort: