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], eq(mod(%, 2), 0))  // true (all even)
all([1, 2, 3], gt(%, 0))          // true (all positive)
all([1, 2, 3], gt(%, 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"}

assoc-in core

fn (coll: Map | Vec, path: Vec, value: Any): Map | Vec

Immutably set a value at a nested path, creating intermediate maps as needed.

Returns a new structure with the value set at the given path. Intermediate maps are created if they don't exist.

Example

assoc-in({}, ["a", "b"], 1)
// {a: {b: 1}}

config {db: {host: "localhost", port: 5432}}
assoc-in(config, ["db", "port"], 5433)
// {db: {host: "localhost", port: 5433}}

// Preserves sibling keys
assoc-in({a: {b: 1, c: 2}}, ["a", "b"], 99)
// {a: {b: 99, c: 2}}

assoc-some core

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

Associate a key-value pair with a map only if the value is not null. Returns the map unchanged if the value is null. Pipe-friendly.

Example

assoc-some({a: 1}, "b", 2)       // {a: 1, b: 2}
assoc-some({a: 1}, "b", null)    // {a: 1}

// Pipe-friendly for building maps with optional fields
{name: "Alice"}
  |> assoc-some("email", user.email)
  |> assoc-some("phone", user.phone)
  |> assoc-some("age", user.age)

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], gt(%, 2))
// [3, 4, 5]

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

filter-keys core

fn (m: Map, predicate: Fn): Map

Return a new map keeping only entries where the key satisfies predicate.

Example

filter-keys({name: "Alice", age: 30, email: "a@b.com"}, ne(%, "age"))
// {name: "Alice", email: "a@b.com"}

// Keep only keys starting with "db_"
config {db_host: "localhost", db_port: 5432, app_name: "myapp"}
filter-keys(config, starts-with(%, "db_"))
// {db_host: "localhost", db_port: 5432}

filter-vals core

fn (m: Map, predicate: Fn): Map

Return a new map keeping only entries where the value satisfies predicate.

Example

filter-vals({a: 1, b: null, c: 3, d: null}, is-some)
// {a: 1, c: 3}

filter-vals({x: 10, y: -5, z: 20}, gt(%, 0))
// {x: 10, z: 20}

// Remove empty strings
filter-vals({name: "Alice", phone: "", email: "a@b.com"}, not(eq(%, "")))
// {name: "Alice", email: "a@b.com"}

find-first core

fn (coll: Vec, predicate: Fn): Any

Return the first element of coll that satisfies predicate, or null if none match. Short-circuits: stops iterating as soon as a match is found.

Example

find-first([1, 2, 3, 4, 5], gt(%, 3))
// 4

find-first([1, 2, 3], gt(%, 10))
// null

// Find a user by email
users [{name: "Alice", email: "a@b.com"}, {name: "Bob", email: "b@b.com"}]
find-first(users, eq(%.email, "b@b.com"))
// {name: "Bob", email: "b@b.com"}

// With or for a default
or(find-first(items, %.featured), first(items))

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]

frequencies core

fn (coll: Vec): Map

Count the number of occurrences of each element in a collection. Returns a map from element to count.

Example

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

frequencies([1, 2, 2, 3, 3, 3])
// {1: 1, 2: 2, 3: 3}

// Count word occurrences
words split("the cat sat on the mat", " ")
frequencies(words)
// {the: 2, cat: 1, sat: 1, on: 1, mat: 1}

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

get-in core

fn (coll: Map | Vec, path: Vec): Any
fn (coll: Map | Vec, path: Vec, default: Any): Any

Walk a path of keys through nested Maps/Vecs.

Returns the value at the nested path, or null (or a default) if any key is missing.

Example

data {users: [{name: "Alice"}, {name: "Bob"}]}

get-in(data, ["users", 0, "name"])
// "Alice"

get-in(data, ["missing", "path"])
// null

get-in(data, ["missing"], "fallback")
// "fallback"

// Deeply nested config
config {db: {host: "localhost", port: 5432}}
get-in(config, ["db", "port"])
// 5432

group-by core

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

Group elements of a collection by a key function. Returns a map from key to a vector of elements that produced that key.

Example

orders [
  {id: 1, status: "pending"},
  {id: 2, status: "shipped"},
  {id: 3, status: "pending"},
  {id: 4, status: "delivered"},
  {id: 5, status: "shipped"}
]

group-by(orders, %.status)
// {
//   pending:   [{id: 1, ...}, {id: 3, ...}],
//   shipped:   [{id: 2, ...}, {id: 5, ...}],
//   delivered: [{id: 4, ...}]
// }

// Group numbers by even/odd
group-by([1, 2, 3, 4, 5, 6], if(eq(mod(%, 2), 0), "even", "odd"))
// {odd: [1, 3, 5], even: [2, 4, 6]}

index-by core

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

Index a collection by a key function, returning a map from key to element. If multiple elements produce the same key, the last one wins.

Example

users [
  {id: 1, name: "Alice"},
  {id: 2, name: "Bob"},
  {id: 3, name: "Carol"}
]

index-by(users, %.id)
// {1: {id: 1, name: "Alice"}, 2: {id: 2, name: "Bob"}, 3: {id: 3, name: "Carol"}}

// Quick lookup after indexing
by-id index-by(users, %.id)
get(by-id, 2).name  // "Bob"

// Index by a derived key
index-by(["apple", "banana", "cherry"], first)
// {a: "apple", b: "banana", c: "cherry"}

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], mul(%, 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"]

map-keys core

fn (m: Map, func: Fn): Map

Apply a function to every key in a map, returning a new map with transformed keys.

Example

map-keys({hello: 1, world: 2}, uppercase)
// {HELLO: 1, WORLD: 2}

map-keys({first_name: "Alice", last_name: "Smith"}, replace(%, "_", "-"))
// {first-name: "Alice", last-name: "Smith"}

map-vals core

fn (m: Map, func: Fn): Map

Apply a function to every value in a map, returning a new map with transformed values.

Example

map-vals({a: 1, b: 2, c: 3}, mul(%, 10))
// {a: 10, b: 20, c: 30}

map-vals({name: "alice", city: "paris"}, uppercase)
// {name: "ALICE", city: "PARIS"}

// Coerce all values to strings
map-vals({a: 1, b: true, c: null}, Str)
// {a: "1", b: "true", c: "null"}

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], [%, mul(%, 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], %)
// [[1, 1], [2, 2], [3]]

partition-by(["a", "ab", "abc", "b"], length(%))
// [["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, ::hot::http/get(%))

postwalk core

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

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

Example

postwalk(if(is-int(%), mul(%, 2), %), [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(if(is-int(%), mul(%, 2), %), [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. Supports early termination: return reduced(value) from the reducer to stop iteration immediately and return value.

Example

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

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

// Short-circuit: stop when sum exceeds 5
reduce([1, 2, 3, 4, 5], (acc, x) {
    total add(acc, x)
    if(gt(total, 5), reduced(total), total)
}, 0)
// 6

reduced core

fn (value: Any): Reduced

Signal early termination from inside a reduce. When the reducer returns reduced(x), reduce immediately stops and returns x. Similar to Clojure's reduced.

Example

// Find first negative number via reduce (stops at -3)
reduce([1, 2, -3, 4, 5], (acc, x) {
    if(lt(x, 0), reduced(x), acc)
}, null)
// -3

// Sum until total exceeds a threshold
reduce([10, 20, 30, 40], (total, x) {
    new-total add(total, x)
    if(gt(new-total, 50), reduced(new-total), new-total)
}, 0)
// 60

// Short-circuit search with accumulation
reduce(orders, (acc, order) {
    if(eq(order.status, "urgent"), reduced(order), acc)
}, null)

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], gt(%, 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], gt(%, 3))   // true
some([1, 2, 3], gt(%, 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, %.age)
// [{name: "Alice", age: 25}, {name: "Bob", age: 30}]

update core

fn (map: Map, key: Any, func: Fn): Map

Apply a function to the value at key in a map, returning a new map. If the key doesn't exist, func receives null.

Example

update({count: 1}, "count", add(%, 1))
// {count: 2}

update({name: "alice"}, "name", uppercase)
// {name: "ALICE"}

// Key doesn't exist — func receives null
update({}, "count", or(%, 0) |> add(1))
// {count: 1}

// Pipe-friendly
{hits: 0, name: "test"}
  |> update("hits", add(%, 1))
  |> update("name", uppercase)
// {hits: 1, name: "TEST"}

update-in core

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

Apply a function to the value at a nested path.

Like assoc-in, but instead of setting a value directly, applies a function to the current value at the path.

Example

update-in({a: {b: 1}}, ["a", "b"], add(%, 10))
// {a: {b: 11}}

config {db: {port: 5432, retries: 3}}
config |> update-in(["db", "retries"], add(%, 1))
// {db: {port: 5432, retries: 4}}

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(
    if(is-int(%), mul(%, 2), %),
    %,
    {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}

Types

Reduced core

Reduced type {
    value: Any
}

Wrapper type that signals early termination from reduce. When a reducer function returns Reduced, reduce stops iterating and returns the unwrapped value. Use the reduced function to create.

Fields

  • value - The final accumulator value to return