Skip to main content

Functions: Type

Kahuna provides functions to check the type of a variable and to cast values between supported types, helping developers write safer and more predictable logic.

Type Checking Functions

FunctionDescriptionExample
is_null(x)Returns true if x is nullis_null(null)true
is_bool(x)Returns true if x is a booleanis_bool(true)true
is_int(x)Returns true if x is an integeris_int(42)true
is_double(x)Returns true if x is an doubleis_double(42.5)true
is_string(x)Returns true if x is a stringis_string("hello")true
is_bytes(x)Returns true if x is a byte streamis_bytes(some_bytes)true
is_array(x)Returns true if x is an arrayis_array([1, 2, 3])true

Type Casting Functions

FunctionDescriptionExample
to_bool(x)Casts x to a booleanto_bool("true")true
to_int(x)Casts x to a int numberto_int("42")42
to_double(x)Casts x to a doubleto_float("42.5")42.5
to_string(x)Converts x to a stringto_string(99)"99"
to_bytes(x)Converts x to a byte streamto_bytes("99")[57, 57]
to_array(x)Casts a value to an array (if possible)to_array("a,b,c")["a","b","c"]

These functions are especially useful in dynamic scripting scenarios, when working with user input, or reading heterogeneous data from the key/value store.