Fix the Flavors: Solution Review
Solution review.
We'll cover the following...
We know from the last exercise that lensPath is the easiest way to focus on everyone’s favorite flavor.
Then combining it with map and view will fetch them.
But now there’s work to do in between. Before view, we need a setter lens. Unfortunately set is only good for static values.
Uppercasing Flavors
over, however, lets us set using functions! We can use Ramda’s toUpper function to uppercase all the flavors.
Again, it’s a list of employees so map's necessary here. over focuses on an object using the favoriteFlavor lens, and uppercases its value.
That returns a new object with the modified flavors.
Passing that new array to map(view) returns the capitalized flavors.
Appending to Flavors
But wait there’s more! We must also append “IS A GREAT FLAVOR” to each of them.
We could combine that with toUpper using good ol’ pipe.
This does the job, but not very eloquently. Look at that nesting!
Let’s create a helper function, emphasize.
Good, let’s go a step further.
Remember that lenses compose too. We don’t need to separate them and call map twice!