Light Dark

Types

Any core

fn (value: Any): Any

Any type. Accepts any value (no type constraint).

Example

// Any is used in function signatures to accept any type
process fn (value: Any): Str { Str(value) }

Bool core

fn (value: Any): Bool

Boolean type. Convert any value to boolean (truthiness).

Example

Bool(1)       // true
Bool(0)       // false
Bool("")      // false
Bool("hi")    // true
Bool(null)    // false

Byte core

fn (value: Byte): Byte

Single byte type (0-255).

Example

b Byte(65)   // ASCII 'A'
Int(b)       // 65

Bytes core

fn (value: Bytes): Bytes

Byte array type for binary data.

Example

data Bytes([72, 105])  // "Hi" as bytes
::hot::base64/encode(data)  // "SGk="

Dec core

fn (value: Int | Dec): Dec

Decimal type (256-bit precision). Convert numeric values to decimal.

Example

Dec(42)         // 42.0
Dec(3.14159)    // 3.14159
div(Dec(1), 3)  // 0.333... (high precision)

Fn core

fn (value: Str | Fn): Fn

Function reference type.

Example

f Fn("add")    // Reference to add function
f(1, 2)         // 3

Int core

fn (value: Int | Dec): Int

Integer type. Convert numeric values to integer (truncates decimals).

Example

Int(42)      // 42
Int(3.7)     // 3
Int(-2.9)    // -2

Map core

fn (value: Any): Map

Map (object) type. Convert value to a map.

Example

Map([["a", 1], ["b", 2]])  // {"a": 1, "b": 2}

Namespace core

fn (value: Str | Namespace): Namespace

Namespace reference type.

Example

ns Namespace("::hot::str")
// Reference to the ::hot::str namespace

Null core

fn (): Null

Null type. Represents absence of a value.

Example

Null()       // null
eq(n, null)  // check for null

Result core

A enum (variant union) type representing either success (Ok) or failure (Err).

Example

success Result.Ok(42)
failure Result.Err("Something went wrong")

success  // 42
failure  // "Something went wrong"

is-ok(success)   // true
is-err(failure)  // true

// Or use the convenience functions:
success ok(42)
failure err("Something went wrong")

Str core

fn (value: Any): Str

String type. Convert any value to a string.

Example

Str(42)         // "42"
Str(true)       // "true"
Str([1, 2, 3])  // "[1, 2, 3]"

Var core

fn (value: Str | Var): Var

Variable reference type.

Example

v Var("my-var")
// Reference to a variable by name

Vec core

fn (value: Any): Vec

Vector (array) type. Convert value to a vector.

Example

Vec("abc")     // ["a", "b", "c"]
Vec({"a": 1})  // [["a", 1]]

Functions

err core

fn (value: Any): Result

Wrap value in an error Result.Err variant.

Example

err("Not found")           // {$type: "::hot::type/Result.Err", $val: "Not found"}
err({"code": 404})         // {$type: "::hot::type/Result.Err", $val: {"code": 404}}

if(eq(user, null), err("User not found"), ok(user))

is-any core

fn (value: Any): Bool

Return true if value is Any (always true).

Example

is-any("anything")  // true
is-any(null)        // true

is-bool core

fn (value: Any): Bool

Return true if value is a Bool.

Example

is-bool(true)   // true
is-bool(false)  // true
is-bool(1)      // false

is-byte core

fn (value: Any): Bool

Return true if value is a Byte.

Example

is-byte(255)  // depends on context

is-bytes core

fn (value: Any): Bool

Return true if value is a Bytes.

Example

data read-file-bytes("file.bin")
is-bytes(data)  // true

is-dec core

fn (value: Any): Bool

Return true if value is a Dec.

Example

is-dec(3.14)   // true
is-dec(42)     // false (Int, not Dec)

is-err core

fn (lazy result: Any): Bool

Return true if result is an error.

Example

is-err(Result.Err("failed"))    // true
is-err(Result.Ok(42))           // false

result fetch-data()
if(is-err(result), println(result.$val), process(result.$val))

is-fn core

fn (value: Any): Bool

Return true if value is a Fn.

Example

is-fn(::hot::math/add)  // true
is-fn("add")            // false
is-fn((x) { x })        // true (lambda)

is-int core

fn (value: Any): Bool

Return true if value is an Int.

Example

is-int(42)     // true
is-int(3.14)   // false
is-int("42")   // false

is-map core

fn (value: Any): Bool

Return true if value is a Map.

Example

is-map({"a": 1})  // true
is-map({})        // true
is-map([1, 2])    // false

is-namespace core

fn (value: Any): Bool

Return true if value is a Namespace.

Example

is-namespace(Namespace("::hot::str"))  // true

is-null core

fn (value: Any): Bool

Return true if value is Null.

Example

is-null(null)    // true
is-null(false)   // false
is-null("")      // false

is-ok core

fn (lazy result: Any): Bool

Return true if result is ok (has a success value).

Example

is-ok(Result.Ok(42))            // true
is-ok(Result.Err("failed"))     // false

result safe-divide(10, 2)
if(is-ok(result), result.$val, 0)

is-result core

fn (value: Any): Bool

Return true if value is a Result type.

Example

is-result(ok(42))        // true
is-result(err("fail"))   // true
is-result(42)            // false

is-some core

fn (value: Any): Bool

Return true if value is not Null.

Example

is-some("hello")  // true
is-some(0)        // true
is-some(null)     // false

is-str core

fn (value: Any): Bool

Return true if value is a Str.

Example

is-str("hello")  // true
is-str(42)       // false

is-type core

fn (lazy val, type-ref)

Return true if value conforms to type-ref.

Example

is-type("hello", Str)  // true
is-type(42, Int)        // true
is-type([1, 2], Vec)    // true
is-type("hello", Int)  // false

// Works with pipes
my-value |> is-type(Str)

For custom types, use is-type with the type name:

Point type { x: Int, y: Int }
p Point({x: 1, y: 2})
is-type(p, Point)  // true

Works with Result types without triggering auto-unwrap:

result err("oops")
is-type(result, Result)  // true

is-var core

fn (value: Any): Bool

Return true if value is a Var.

Example

is-var(Var("::hot::str/split"))  // true

is-vec core

fn (value: Any): Bool

Return true if value is a Vec.

Example

is-vec([1, 2, 3])  // true
is-vec([])         // true
is-vec({"a": 1})   // false

ok core

fn (value: Any): Result

Wrap value in a successful Result.Ok variant.

Example

ok(42)           // {$type: "::hot::type/Result.Ok", $val: 42}
ok("success")    // {$type: "::hot::type/Result.Ok", $val: "success"}

result ok(get-user(id))
if(is-ok(result), result.$val, "not found")

untype core

fn (form: Any): Any

Transform Hot typed structures to simple Val structures by removing $type and $val metadata.

Example

// Given a typed structure
user User({"name": "Alice"})

// Remove type wrapper
untype(user)  // {"name": "Alice"}