Skip to main content
Version: v1.10.0

under

Function

under the underlying value

Synopsis

under(val: any) -> any

Description

The under function returns the value underlying the argument val:

  • for unions, it returns the value as its elemental type of the union,
  • for errors, it returns the value that the error wraps,
  • for types, it returns the value typed as typeunder() indicates; otherwise,
  • it returns val unmodified.

Examples

Unions are unwrapped:

echo '1((int64,string)) "foo"((int64,string))' | zq -z 'yield this' -
echo '1((int64,string)) "foo"((int64,string))' | zq -z 'yield under(this)' -

=>

1((int64,string))
"foo"((int64,string))
1
"foo"

Errors are unwrapped:

echo 'error("foo") error({err:"message"})' | zq -z 'yield this' -
echo 'error("foo") error({err:"message"})' | zq -z 'yield under(this)' -

=>

error("foo")
error({err:"message"})
"foo"
{err:"message"}

Values of named types are unwrapped:

echo '80(port=uint16)' | zq -z 'yield this' -
echo '80(port=uint16)' | zq -z 'yield under(this)' -

=>

80(port=uint16)
80(uint16)

Values that are not wrapped are unmodified:

echo '1 "foo" <int16> {x:1}' | zq -z 'yield under(this)' -

=>

1
"foo"
<int16>
{x:1}