Adds nested builder functions#3305
Conversation
|
This feels a bit underspecified and asymmetric, as if you're scratching one specific itch but not solving all itches. To be concrete, I would expect just the builder of a message to get a DSL long before this specific use case. |
|
It is underspecified but figured I'd take a crack at what's been bothering me. The itch is: Expanding on the example above: let's say
If I want to update Getting something closer to below would be a win IMO: Hopefully that highlights the use case better. |
|
Yeah I get that for sure. With that example API I'm a bit worried that there exists a top-level I think I would prefer to separate top-level creation functions from the create-or-update builder members somehow by name. For at least the top-level ones, I don't think prefixing with "build" is terrible (like The members can then stay named as the fields rather than the types. So let's say val p = buildPerson {
address {
// ...
}
}or val p = buildPerson {
address = buildMailingAddress {
// ...
}
} |
|
And then I'm tempted to round that out with like |
The nullable receiver approach could be a good middle ground to reduce some of the create-or-update boilerplate, while having a less hazardous API ... don't know if |
I've found myself repeating code working with nested messages. Something along the lines of:
I think it'd be cool to inline that into wire generated code.
Example:
Will generate a new function for the nested message field "address":
Which can be used like so: