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

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

# spq
values {yes:is(this, <float64>),no:is(this, <int64>)}
# input
1.
# expected output
{yes:true,no:false}

Test for a given input’s record type or “shape”

# spq
values is(this, <{s:string}>)
# input
{s:"hello"}
# expected output
true

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

# spq
values is(this, <{s:string}>)
# input
{s:"hello"}::=foo
# expected output
false

# spq
values is(this, <foo>)
# input
{s:"hello"}::=foo
# expected output
true

To test the underlying type, just use ==

# spq
values under(typeof(this))==<{s:string}>
# input
{s:"hello"}::=foo
# expected output
true