Understanding the use of Optics in Nested and Optional Data within Elixir

97
clicks
Understanding the use of Optics in Nested and Optional Data within Elixir
The post explores how to work with nested data structures in Elixir, specifically in the context of a spacecraft's telemetry system, which includes thruster and navigation data. It illustrates how to compose different optics—Iso, Lens, Prism, and Traversal—to handle unit conversions and optional data gracefully. The author presents an example of how to convert between LbfSeconds and NewtonSeconds for thruster impulses and navigation targets. Additionally, the use of Prisms is highlighted for optional data, particularly when communication with a navigation module may fail. The article also touches on vendor decisions in system design, showing how explicit isomorphisms between different data schemas can enable flexibility without significant system refactoring. Overall, the content emphasizes the importance of making data equivalence explicit to facilitate easier system maintenance and upgrades.

© HashMerge 2026