Lenses, as we saw in the previous section, are useful for working with product types. However, prisms are useful for working with sum types. But what are they? (We'll look at products and unions in more detail in the Data types section of the next chapter.) The idea is that a product type is always built out of the same options, such as an object from a class, while a sum type will likely have different structures—extra or missing attributes, for example. When you use a lens, you assume that the object that you'll be applying it to has a known structure with no variations, but what do you use if the object may have different structures? The answer is prisms. Let's take a look at how they are used first; then, we'll look at their implementation. ...

Get Mastering JavaScript Functional Programming - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.