January 2020
Intermediate to advanced
470 pages
11h 13m
English
The simplest way to implement a lens is by representing it with an object with just two properties: a getter and a setter. In this case, we'd have something like this:
const lens = (getter, setter) => ({getter, setter});
This is easy to understand: given a getter and a setter, lens() just creates an object with those two attributes. With this definition, lensProp() would be as follows:
const lensProp = attr => lens(getField(attr), setField(attr));
The first function, lensProp(), creates a getter/setter pair by using getField() and setField(); very straightforward. Now that we have our lens, how do we implement the three basic functions that we saw in the previous section? Viewing an attribute just requires ...
Read now
Unlock full access