Skip to content

Surgically modifying an optional field (replacement for "quiet" idiom) #7272

Description

@philrz

Before the quiet function was removed in #7232, it could be used in a handy idiom to surgically modify a field of a given name that might sometimes be present and sometimes absent, like this cast:

$ super -version &&
  echo '
    {"log_time":"Tue Sep  1 18:49:02 PDT 2026", "a":1}
    {"foo":"bar","a":2}' |
  super -c "put log_time:=quiet(log_time::time)" -

Version: v0.3.0-333-g25481b8bc

{log_time:2026-09-02T01:49:02Z,a:1}
{foo:"bar",a:2}

Now that quiet is gone, it's become a bit more cumbersome to express the equivalent of this.

Details

At the time this issue is being opened, super is at commit 7a03e7f. The quiet function was most recently available in commit 25481b8 as shown above.

The reason the quiet was so useful here is because without it, when the field was not present, an error("missing") appears at the location of the attempted cast.

$ super -version &&
  echo '
    {"log_time":"Tue Sep  1 18:49:02 PDT 2026", "a":1}
    {"foo":"bar","a":2}' |
  super -c "put log_time:=log_time::time" -

Version: v0.3.0-361-g7a03e7f05

{log_time:2026-09-02T01:49:02Z,a:1}
{foo:"bar",a:2,log_time:error("missing")}

The best way I've come up with to get the equivalent of what we had before uses conditional logic and spread.

$ super -version &&
  echo '
    {"log_time":"Tue Sep  1 18:49:02 PDT 2026", "a":1}
    {"foo":"bar","a":2}' |
  super -c "values has(log_time) ? {...this, log_time: log_time::time} : this" -

Version: v0.3.0-361-g7a03e7f05

{log_time:2026-09-02T01:49:02Z,a:1}
{foo:"bar",a:2}

In a pinch we could document this to encourage it as a new idiom, but it's a lot more typing for a fairly simple operation.

It's been discussed that in this era of "none" we may be able to introduce a new shorthand that covers this case in a straightforward way.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions