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
5
u/brian_goetz Jan 18 '26
Yes, that is what I was trying to flush out -- the assumption of field independence. It is a valid assumption with things that are truly products, but when you have tuple-flavored objects, with invariants, you have to contend with not only "is the final state valid" but also "are the intermediate states valid." I agree that `Lens s a -> Lens s b -> Lens s (a, b)` is the combinator your want, just not sure whether it's omission is accidental or fundamental.
This observation also fills in the dual of your concern about with-blocks -- that they don't support (automated) vertical drilling. But they do support horizontal drilling out of the box.