Functional Programming (FP) is a great programming paradigm. This is because programming with pure functions gives developers several advantages, such as code that is concise, predictable, and easier to test. However, it turns out there are some cases where code written using the Functional paradigm is more verbose than with the Object-Oriented paradigm (OOP). This happens especially because, in Functional Programming, we must work with immutable data structures. For example, when we have a structure with deeply nested records, complications start to arise when trying to modify a part of it. That’s because we can’t actually modify the original structure, so we need to create a completely new one that’s almost exactly the same as the original. However, it will need a little modification, and there’s usually a lot of boilerplate code we will have to write to solve that problem. In OOP, we can just change the value we want, and that’s it. However, when we start working with deeply nested collections, not even OOP has a good solution to avoid boilerplate. The good news is that in FP we have a tool at our disposal for addressing these problems. It’s called Optics.
In the Scala world, there are some libraries that offer implementations of optics. In this document, we are going to focus on ZIO Optics, which is a new library in the ZIO ecosystem.
Here’s what you’ll learn:
Not a fan of reading online?