is
Function
is — test a value’s type
Synopsis
is(val: any, t: type) -> bool
Description
The is function returns true if the argument val
is of type t
.
The is function is shorthand for typeof(val)==t
.
Examples
Test simple types:
values {yes:is(this, <float64>),no:is(this, <int64>)}
1.
Loading...
echo '1.' \
| super -s -c 'values {yes:is(this, <float64>),no:is(this, <int64>)}' -
Test for a given input’s record type or “shape”:
values is(this, <{s:string}>)
{s:"hello"}
Loading...
echo '{s:"hello"}' \
| super -s -c 'values is(this, <{s:string}>)' -
If you test a named type with its underlying type, the types are different, but if you use the type name or typeof and under functions, there is a match:
values is(this, <{s:string}>)
{s:"hello"}::=foo
Loading...
echo '{s:"hello"}::=foo' \
| super -s -c 'values is(this, <{s:string}>)' -
values is(this, <foo>)
{s:"hello"}::=foo
Loading...
echo '{s:"hello"}::=foo' \
| super -s -c 'values is(this, <foo>)' -
To test the underlying type, just use ==
:
values under(typeof(this))==<{s:string}>
{s:"hello"}::=foo
Loading...
echo '{s:"hello"}::=foo' \
| super -s -c 'values under(typeof(this))==<{s:string}>' -