-
Notifications
You must be signed in to change notification settings - Fork 278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request: Generate update(UnaryOperator)-methods along withers (new style flag?) #1408
Comments
Thank you for the feature request. The idea is good, maybe something like that was planned before, but we always tried to keep number of generated methods minimal. Ideally, we would have some sort of extensibility mechanism to add methods like these. The encodings (https://immutables.github.io/encoding.html) are a kind of extensibility I'm talking about, but these are per type, not applicable to any attribute. Indeed, this can be activated by a style flag in a form of naming pattern, empty by default - disabled ( |
That was fast! Thank you! Hopefully records get withers some day and they creep up to regular immutable classes too: |
yep, all good stuff comes to java only if you don't wait for it ;) |
#1408 withUnaryOperator style flag/naming template
Currently transforming Immutables-generated objects requires to write rather clumsy code.
And it gets worse with nested objects.
Simple improvement could be if Immutables would generate update-methods along with withers to allow transforming nested objects more cleanly. Basic update-method signature for a
String foo
-property in ImmutableBar -class would be:Which would allow to write:
Or if the
foo
-property would be another immutables -generated object instead of String:Currently updaters can be written by hand to the template class / interface if needed, but I see no reason why they could not be generated.
Also Optional (and Vavr Option etc.) could be taken account and offer an updater method which would transform the value only if it is present but this feature is not a must.
Chaining and doing this for multiple fields is of course inefficient but nothing prevents abusing withers in the same way.
The text was updated successfully, but these errors were encountered: