
TypeScript 4 Design Patterns and Best Practices
By :

A functional lens is another name for an object's getter
and setter
methods paired together in a tuple. We call them like that mainly because the idea is to have a functional way to compose getters and setters without modifying an existing object. So, you use a lens to create scopes over objects, and then you use those scopes if you want to interface with the objects in a composable way.
You can think of lenses as similar to having an Adapter pattern where the Target is the object you want to adapt and the lenses are the Adaptees. You create lenses that adapt over an object type and you can get or set their properties. The main benefit here is that the Lenses
object is generic and you can compose it in a functional way.
Let's explain more about lenses next and how to implement them in TypeScript.
A basic lens interface supports two methods: Get
is for getting a property of type A
from an object of type T...