Are there any proposals to improve ergonomics for ...
# language-proposals
n
Are there any proposals to improve ergonomics for updating nested members of immutable data classes? I've seen lens libraries can help a bit but they only go so far given the tools the language currently provides
r
The Arrow meta team is porting the Arrow Optics DSL to a compiler plugin so it’s available for all sealed and data classes in a synthetic projection over values and it will be available before Arrow goes stable around 1.4.2. We will then submit a KEEP or whatever Jetbrains prefer for proposals to be considered as sane replacement for nested copies. Looks like this in its static version
Copy code
Employee.company.address.street.name.modify(employee, String::toUpperCase)
Employee
is the companion or any other object you wish to project the api over. The api aims to be synthetic a la carte so only generated in types and paths were used. If the KEEP or something similar is ever accepted we will drop the plugin but at least the functionality will be available for anyone to use it if there is no changes to the nested copy problem.
n
Ah that's really cool to hear! Two follow up questions. Is there a timeline for that to happen? And second, is there a reason that you can't get that syntax with the current approach of arrow of generating code via annotations? It seemed possible when I thought about it, but not 100% sure.
r
Arrow already provided that syntax with kapt and it's possible to do it also just with the compiler codegen. Using kapt comes at the cost of having to expand all properties as lenses etc. In a complex tree ADT that is quite a bit of bytecode, more than just 'copy'. We want to remove the abstraction itself and use the compiler to only generate structures when they are used at the call site unless the user purposely exports all of it in the binary. The timeline for this to happen as a compiler plugin is asap starting next week since @Rachel got arrow to upgrade to 1.4 and meta is ready to start being ported. We may take a few weeks or 2-3 months depending on priorities and who is helping. Arrow stable comes out when IR is no longer experimental since meta depends on IR and makes no attempt to support the ASM codegen in the meantime we are porting Arrow to be encoded with meta to test meta's features in the arrow code base