lens()
lens<
T,V>(getter,setter):Lens<T,V>
Focus on and manipulate a specific property or substructure within an object.
Type Parameters
T
T
The type of the object being inspected.
V
V
The type of the property value.
Parameters
getter
LenseGet<T, V>
The lens get function to use.
setter
LenseSet<T, V>
The lens set function to use.
Returns
Lens<T, V>
Remarks
pure function
Example
const nameLens = lens(
(person: Person) => person.name,
(person, name) => ({ ...person, name })
);
const name = nameLens.get(person);
const { get: getUsername, set: setUsername } = lens(
(user: User) => property(user)('username'),
(user, name) => associateDeep(user)('username')(name)
);
const username = getUsername(user);