Optics is a functional programming concept that can help us to reduce the amount of code that we need to write and make operations more readable. The benefits of using optics are particularly noticeable when we are working with immutable data structures. All optics are a way to get and set properties in an object. In fact, we can think about optics as an alternative to getters and setters in object-oriented programming.
Optics can be categorized into two main groups—lenses and prisms. As we learned in Chapter 7, Category Theory, algebraic data types can be defined in terms of sum and product types. A lens is used to work with product types (for example, tuples and objects) and a prism is used to work with sum types (for example, discriminated ...