Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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 name-typed values, it returns the value with the named type’s underlying type,
  • for type values, it removes a named type if one exists; otherwise,
  • it returns val unmodified.

Examples


Unions are unwrapped

# spq
values this
# input
1::(int64|string)
"foo"::(int64|string)
# expected output
1::(int64|string)
"foo"::(int64|string)

# spq
values under(this)
# input
1::(int64|string)
"foo"::(int64|string)
# expected output
1
"foo"

Errors are unwrapped

# spq
values this
# input
error("foo")
error({err:"message"})
# expected output
error("foo")
error({err:"message"})

# spq
values under(this)
# input
error("foo")
error({err:"message"})
# expected output
"foo"
{err:"message"}

Values of named types are unwrapped

# spq
values this
# input
80::(port=uint16)
# expected output
80::(port=uint16)

# spq
values under(this)
# input
80::(port=uint16)
# expected output
80::uint16

Values that are not wrapped are unmodified

# spq
values under(this)
# input
1
"foo"
<int16>
{x:1}
# expected output
1
"foo"
<int16>
{x:1}