More optics in Funx: name your shareable boundaries with prisms

Includes a Livebook.

Like a Lens, a Prism is composable. In Elixir, it can also help manage missing keys or expected nils, but that is incidental. A Prism models conditional existence: a focus that exists only on certain branches of a sum type.

Let’s say we are building a system to process transactions. A transaction can be a purchase or a refund, and it can be paid by check or credit card.

The tricky part is not extracting fields. It is deciding which payment operations apply.

1 Like