Skip to main content
Version: v1.6.0

is

Function

is test a value's type

Synopsis

is(t: type) -> bool
is(val: any, t: type) -> bool

Description

The is function returns true if the argument val is of type t. If val is omitted, it defaults to this. The is function is shorthand for typeof(val)==t.

Examples

Test simple types:

echo '1.' | zq -z 'yield {yes:is(<float64>),no:is(<int64>)}' -

=>

{yes:true,no:false}

Test for a given input's record type or "shape":

echo '{s:"hello"}' | zq -z 'yield is(<{s:string}>)' -

=>

true

If you test a named type with it's underlying type, the types are different, but if you use the type name or typeunder function, there is a match:

echo '{s:"hello"}(=foo)' | zq -z 'yield is(<{s:string}>)' -
echo '{s:"hello"}(=foo)' | zq -z 'yield is(<foo>)' -

=>

false
true

To test the underlying type, just use ==:

echo '{s:"hello"}(=foo)' | zq -z 'yield typeunder(this)==<{s:string}>' -

=>

true