January 2020
Intermediate to advanced
470 pages
11h 13m
English
Working with prisms is similar to using lenses, except for what happens when an attribute is not present. Let's take a look at an example from the previous section:
const author = { user: "fkereki", name: { first: "Federico", middle: "", last: "Kereki" }, books: [ { name: "GWT", year: 2010 }, { name: "FP", year: 2017 }, { name: "CB", year: 2018 } ]};
If we wanted to access the user attribute using prisms, we would write something like the following—don't worry about the details; we'll look at the actual implementation later:
const pUser = prismProp("user");console.log(review(pUser, author).toString()); /* fkereki*/
Here, we define a prism using a prismProp() function, which parallels our previous lensProp() one. Then, ...
Read now
Unlock full access