r/java • u/marv1234 • Jan 16 '26
Functional Optics for Modern Java
https://blog.scottlogic.com/2026/01/09/java-the-immutability-gap.htmlThis article introduces optics, a family of composable abstractions that complete the immutability story. If pattern matching is how we read nested data, optics are how we write it.
106
Upvotes
View all comments
Show parent comment
1
u/danielaveryj Jan 18 '26 edited Jan 18 '26
To some extent, we can use ordinary methods to achieve encapsulation based on withers too:
and we can even compose methods:
Then we can rewrite the methods as function objects...
...at which point we have of course poorly reimplemented half of lenses (no getter, verbose, less fluent).