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 named values, it returns the value with the name removed,
- for type values, it removes the named type if one exists; otherwise,
- it returns
val
unmodified.
Examples
Unions are unwrapped:
yield this
1((int64,string))
"foo"((int64,string))
Loading...
echo '1((int64,string))
"foo"((int64,string))' \
| super -z -c 'yield this' -
yield under(this)
1((int64,string))
"foo"((int64,string))
Loading...
echo '1((int64,string))
"foo"((int64,string))' \
| super -z -c 'yield under(this)' -
Errors are unwrapped:
yield this
error("foo")
error({err:"message"})
Loading...
echo 'error("foo")
error({err:"message"})' \
| super -z -c 'yield this' -
yield under(this)
error("foo")
error({err:"message"})
Loading...
echo 'error("foo")
error({err:"message"})' \
| super -z -c 'yield under(this)' -
Values of named types are unwrapped:
yield this
80(port=uint16)
Loading...
echo '80(port=uint16)' \
| super -z -c 'yield this' -
yield under(this)
80(port=uint16)
Loading...
echo '80(port=uint16)' \
| super -z -c 'yield under(this)' -
Values that are not wrapped are unmodified:
yield under(this)
1
"foo"
<int16>
{x:1}
Loading...
echo '1
"foo"
<int16>
{x:1}' \
| super -z -c 'yield under(this)' -