Skip to content
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

Optional entry support for map and message literal construction #603

Merged
merged 6 commits into from
Nov 8, 2022

Conversation

TristonianJones
Copy link
Collaborator

Introduces parse, type-check, and runtime support for optional entry construction on map and message literals, including:

  • {?key: a.?b} - create a new map with a dynamic key if the field b is set on object a
  • Msg{?item: list[?0]} - create a new Msg with the item field set if the list contains at least one element.

If all of the fields in the object are empty, then using the optional.ofNonZeroValue() call with the result makes it possible to return optional.none() if the value is empty. This is useful for setting optional fields where the value is a map or message type

Msg{
   ?map_value: optional.ofNonZeroValue({
       ?'key': a.?b
   })
}

@TristonianJones TristonianJones marked this pull request as draft November 4, 2022 00:50
@TristonianJones TristonianJones marked this pull request as ready for review November 4, 2022 18:57
jcking
jcking previously approved these changes Nov 7, 2022
@TristonianJones TristonianJones merged commit 218aabe into google:master Nov 8, 2022
@TristonianJones TristonianJones deleted the opt-entry branch November 8, 2022 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants