Light Dark

Functions

all core

fn (coll: Str | Vec | Map, predicate: Fn): Bool

Return true if all elements of coll satisfy predicate.

Example

all([2, 4, 6], (x) { eq(mod(x, 2), 0) })  // true (all even)
all([1, 2, 3], (x) { gt(x, 0) })          // true (all positive)
all([1, 2, 3], (x) { gt(x, 2) })          // false

assoc core

fn (map: Map, key: Any, value: Any): Map

Associate a key-value pair with a map, returning a new map.

Creates a new map with the key-value pair added or updated. Useful for adding keys dynamically (when key is a variable).

Example

assoc({"a": 1}, "b", 2)           // {"a": 1, "b": 2}
assoc({"a": 1}, "a", 42)          // {"a": 42}

// Dynamic key
key "mykey"
assoc({}, key, "value")           // {"mykey": "value"}

butlast core

fn (coll: Str | Vec | Map): Str | Vec | Map

Return everything but the last element of coll.

Example

butlast([1, 2, 3])   // [1, 2]
butlast("hello")    // "hell"

concat core

fn (a: Vec, b: Vec, rest: Vec): Vec
fn (a: Str, b: Str, rest: Str): Str
fn (a: Bytes, b: Bytes, rest: Bytes): Bytes

Concatenate values of the same type (strings, vectors, or bytes).

Example

concat([1, 2], [3, 4])        // [1, 2, 3, 4]
concat("Hello", " ", "World") // "Hello World"
concat(Bytes([1, 2]), Bytes([3, 4]))  // Bytes([1, 2, 3, 4])

delete core

fn (coll: Str | Vec | Map, key-or-index: Str | Int): Str | Vec | Map

Delete key (or index) from collection.

Example

delete([1, 2, 3], 1)          // [1, 3]
delete({"a": 1, "b": 2}, "a") // {"b": 2}
delete("hello", 0)            // "ello"

distinct core

fn (coll: Str | Vec | Map): Str | Vec | Map

Remove duplicate elements from coll.

Example

distinct([1, 2, 2, 3, 3, 3])
// [1, 2, 3]

filter core

fn (coll: Str | Vec | Map, predicate: Fn): Str | Vec | Map

Return elements of coll that satisfy predicate.

Example

filter([1, 2, 3, 4, 5], (x) { gt(x, 2) })
// [3, 4, 5]

filter({"a": 1, "b": 2, "c": 3}, (k, v) { gt(v, 1) })
// [["b", 2], ["c", 3]]

first core

fn (coll: Str | Vec | Map): Any

Return the first element of coll.

Example

first([1, 2, 3])   // 1
first("hello")    // "h"
first([])          // null

flatten core

fn (coll: Str | Vec | Map): Str | Vec | Map

Flatten nested collections by one level.

Example

flatten([[1, 2], [3, [4, 5]], 6])
// [1, 2, 3, 4, 5, 6]

get core

fn (coll: Map | Vec | Str | Bytes, key: Any): Any
fn (coll: Map | Vec | Str | Bytes, key: Any, not-found: Any): Any

Get a value from coll by key or index.

For Map, looks up by key. For Vec, Str, and Bytes, looks up by 0-based index. Returns null if not found (2-arity) or not-found value (3-arity).

Example

// Map lookup
get({"a": 1, "b": 2}, "a")           // 1
get({"a": 1}, "missing")              // null
get({"a": 1}, "missing", "default")  // "default"

// Vec lookup
get([10, 20, 30], 1)                  // 20
get([10, 20], 5)                      // null
get([10, 20], 5, -1)                  // -1

// Str lookup (returns single character)
get("hello", 0)                       // "h"
get("hello", 10)                      // null

// Bytes lookup (returns byte as Int)
get(Bytes([65, 66, 67]), 0)           // 65

interleave core

fn (a: Str | Vec | Map, b: Str | Vec | Map): Str | Vec | Map

Alternate elements from a and b.

Example

interleave([1, 3, 5], [2, 4, 6])
// [1, 2, 3, 4, 5, 6]

interpose core

fn (coll: Str | Vec | Map, separator: Any): Str | Vec | Map

Insert separator between elements of coll.

Example

interpose(["a", "b", "c"], ",")
// ["a", ",", "b", ",", "c"]

is-empty core

fn (coll: Str | Vec | Map): Bool

Return true if coll has no elements.

Example

is-empty([])       // true
is-empty([1])      // false
is-empty("")       // true
is-empty({})       // true

keys core

fn (coll: Str | Vec | Map): Str | Vec | Map

Return the keys of a map or indices of a vector/string.

Example

keys({"a": 1, "b": 2})   // ["a", "b"]
keys([10, 20, 30])        // [0, 1, 2]

last core

fn (coll: Str | Vec | Map): Any

Return the last element of coll.

Example

last([1, 2, 3])   // 3
last("hello")    // "o"

length core

fn (coll: Str | Vec | Map | Bytes): Int

Return the number of elements in coll.

Example

length([1, 2, 3])        // 3
length("hello")          // 5
length({"a": 1, "b": 2}) // 2
length(Bytes([1, 2, 3])) // 3

map core

fn (coll: Str | Vec | Map, func: Fn): Str | Vec | Map

Apply func to each element of coll and return a collection of results.

Example

map([1, 2, 3], (x) { mul(x, 2) })
// [2, 4, 6]

map({"a": 1, "b": 2}, (k, v) { add(v, 10) })
// [11, 12]

map-indexed core

fn (coll: Str | Vec | Map, func: Fn): Str | Vec | Map

Map with indices: call func(index, value) for each element.

Example

map-indexed(["a", "b", "c"], (i, x) { concat(i, ":", x) })
// ["0:a", "1:b", "2:c"]

mapcat core

fn (coll: Str | Vec | Map, f: Fn): Str | Vec | Map

Map f over coll and concatenate the results.

Example

mapcat([1, 2, 3], (x) { [x, mul(x, 10)] })
// [1, 10, 2, 20, 3, 30]

merge core

fn (a: Map, b: Map): Map

Deep merge two maps. Values from b override a.

Example

merge({"a": 1, "b": 2}, {"b": 3, "c": 4})
// {"a": 1, "b": 3, "c": 4}

// Deep merge for nested maps
merge({"x": {"a": 1}}, {"x": {"b": 2}})
// {"x": {"a": 1, "b": 2}}

partition core

fn (coll: Str | Vec | Map, size: Int): Str | Vec | Map

Partition coll into groups of size.

Example

partition([1, 2, 3, 4, 5], 2)
// [[1, 2], [3, 4], [5]]

partition-by core

fn (coll: Str | Vec | Map, func: Fn): Str | Vec | Map

Partition coll into groups when the value of func(x) changes.

Example

partition-by([1, 1, 2, 2, 3], (x) { x })
// [[1, 1], [2, 2], [3]]

partition-by(["a", "ab", "abc", "b"], (x) { length(x) })
// [["a"], ["ab"], ["abc"], ["b"]]

pmap core

fn (coll: Str | Vec | Map, func: Fn): Str | Vec | Map

Parallel map: apply func to each element of coll concurrently.

Example

// Fetch multiple URLs in parallel
urls ["https://api.example.com/a", "https://api.example.com/b"]
pmap(urls, (url) { ::hot::http/get(url) })

postwalk core

fn (f: Fn, form: Any): Any

Post-order walk: apply function to each node after walking children.

Example

postwalk((x) { if(is-int(x), mul(x, 2), x) }, [1, [2, 3]])
// [2, [4, 6]]

postwalk-replace core

fn (replacement-map: Map, form: Any): Any

Replace values in a structure based on a replacement map using post-order walk.

Example

postwalk-replace({"a": "x", "b": "y"}, ["a", ["b", "c"]])
// ["x", ["y", "c"]]

prewalk core

fn (f: Fn, form: Any): Any

Pre-order walk: apply function to each node before walking children.

Example

prewalk((x) { if(is-int(x), mul(x, 2), x) }, [1, [2, 3]])
// [2, [4, 6]]

range core

fn (end: Int | Dec): Vec
fn (start: Int | Dec, end: Int | Dec): Vec
fn (start: Int | Dec, end: Int | Dec, step: Int | Dec): Vec

Generate a sequence from 0 to end (exclusive), or from start to end with optional step.

Example

range(5)          // [0, 1, 2, 3, 4]
range(2, 7)       // [2, 3, 4, 5, 6]
range(0, 10, 2)   // [0, 2, 4, 6, 8]
range(10, 5, -1)  // [10, 9, 8, 7, 6]

reduce core

fn (coll: Str | Vec | Map, reducer: Fn, initial: Any): Any

Reduce coll using reducer(acc, x) starting with initial.

Example

reduce([1, 2, 3, 4], (acc, x) { add(acc, x) }, 0)
// 10

reduce(["a", "b", "c"], (acc, x) { concat(acc, x) }, "")
// "abc"

remove core

fn (coll: Str | Vec | Map, predicate: Fn): Str | Vec | Map

Remove elements of coll that satisfy predicate.

Example

remove([1, 2, 3, 4, 5], (x) { gt(x, 3) })
// [1, 2, 3]

rest core

fn (coll: Str | Vec | Map): Str | Vec | Map

Return everything but the first element of coll.

Example

rest([1, 2, 3])   // [2, 3]
rest("hello")    // "ello"

reverse core

fn (coll: Str | Vec | Map): Str | Vec | Map

Return coll with elements in reverse order.

Example

reverse([1, 2, 3])   // [3, 2, 1]
reverse("hello")    // "olleh"

shuffle core

fn (coll: Str | Vec | Map): Str | Vec | Map

Return a new collection with elements of coll in random order.

Example

shuffle([1, 2, 3, 4, 5])
// [3, 1, 5, 2, 4] (random order)

slice core

fn (coll: Str | Vec | Map | Bytes, start: Int): Str | Vec | Map | Bytes
fn (coll: Str | Vec | Map | Bytes, start: Int, end: Int): Str | Vec | Map | Bytes

Return a subrange from coll from start (inclusive) to optional end (exclusive).

Example

slice([1, 2, 3, 4, 5], 2)      // [3, 4, 5]
slice([1, 2, 3, 4, 5], 1, 4)   // [2, 3, 4]
slice("hello world", 0, 5)    // "hello"
slice(Bytes([1, 2, 3, 4, 5]), 1, 3)  // Bytes([2, 3])

some core

fn (coll: Str | Vec | Map, predicate: Fn): Bool

Return true if any element of coll satisfies predicate.

Example

some([1, 2, 3, 4], (x) { gt(x, 3) })   // true
some([1, 2, 3], (x) { gt(x, 5) })      // false

sort core

fn (coll: Str | Vec | Map): Str | Vec | Map

Sort coll in ascending order.

Example

sort([3, 1, 4, 1, 5, 9])
// [1, 1, 3, 4, 5, 9]

sort-by core

fn (coll: Str | Vec | Map, func: Fn): Str | Vec | Map

Sort coll by keys derived from func(x).

Example

users [{"name": "Bob", "age": 30}, {"name": "Alice", "age": 25}]
sort-by(users, (u) { u.age })
// [{"name": "Alice", "age": 25}, {"name": "Bob", "age": 30}]

vals core

fn (coll: Str | Vec | Map): Str | Vec | Map

Return the values of a collection.

Example

vals({"a": 1, "b": 2})   // [1, 2]
vals([10, 20, 30])        // [10, 20, 30]

walk core

fn (inner: Fn, outer: Fn, form: Any): Any

Walk through a data structure applying inner function to children, then outer function to result.

Example

// Double all numbers in a nested structure
walk(
    (x) { if(is-int(x), mul(x, 2), x) },
    (x) { x },
    {"a": [1, 2], "b": 3}
)
// {"a": [2, 4], "b": 6}

zipmap core

fn (a: Vec, b: Vec): Map

Create a map from keys in a and values in b.

Example

zipmap(["a", "b", "c"], [1, 2, 3])
// {"a": 1, "b": 2, "c": 3}