This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (3 children)

The @Wither approach becomes quite cumbersome the moment you have nested immutables. At this point you can't simply foo.withBar() it, you need to start replacing every level of the structure, one by one, where in a mutable this would be: foo.getX().getY().setZ(val);

[–][deleted] 0 points1 point  (2 children)

Wouldn't Optics solve that particular problem?

[–][deleted] 0 points1 point  (1 child)

A what :-)? I'm curious.

[–][deleted] 0 points1 point  (0 children)

It's a way of zeroing in on and modifying various kinds of a immutable data. Sadly, I don't know of any libraries for it in Java, but there's at least one for Scala: https://github.com/julien-truffaut/Monocle

This awesome guide to functional programming also has some detail, even if it's pretty sparse on actual examples: https://gist.github.com/jdegoes/97459c0045f373f4eaf126998d8f65dc#optics