3 ms·
As others pointed out, you don't need any convenience from a modern language. But what optics (often sloppily referred to as lenses) give you are really powerf
by kqr 2y ago
As others pointed out, you don't need any convenience from a modern language.
But what optics (often sloppily referred to as lenses) give you are really powerful getters and setters. They can do what getters and setters in Python do, but they can also
- target multiple fields in multiple objects at the same time, or
- target fields only when a condition is true,
- they can target deeply nested fields,
- they can target computed values which have a compound effect on the underlying fields,
- they can return a new full object where the targeted fields are transformed by an arbitrary function, etc.
This means optics are extremely broadly useful. They can be used as OO-style getters and setters, but they can also be used to build and navigate JSON objects, or parse HTML content. It's a common interface that can be used for getting and modifying data in any broader context.