Pipes & methods

Pipe operator

The |> operator passes the left-hand value as the first argument to the right-hand function:

cleat
let result = items
    |> filter(fn(x: int) -> bool { return x > 0 })
    |> map(fn(x: int) -> int { return x * 2 })
    |> sum()

This is equivalent to sum(map(filter(items, ...), ...)) but reads top-to-bottom.

Slice methods

MethodSignatureDescription
.len()-> intNumber of elements
.contains(elem)-> boolWhether the slice contains the element
.filter(fn)-> []TKeep elements where fn returns true
.map(fn)-> []UTransform each element
.sum()-> intSum all elements (int slices only)
cleat
let names = ["alice", "bob", "charlie"]
let count = names.len()              // 3
let has_bob = names.contains("bob")  // true

let scores = [85, 92, 78, 95]
let high = scores |> filter(fn(s: int) -> bool { return s > 90 })
let total = scores |> sum()  // 350

Map methods

MethodSignatureDescription
.len()-> intNumber of entries
.contains(key)-> boolWhether the key exists
.keys()-> []KAll keys
.values()-> []VAll values
.remove(key)-> boolRemove entry, return whether it existed
cleat
let m = map[string]int { "a": 1, "b": 2 }
let keys = m.keys()        // ["a", "b"]
m.remove("a")              // true

String interpolation

Expressions inside ${} are evaluated inline:

cleat
io.println("found ${results.len()} results for ${query}")
io.println("status: ${resp.status}, body length: ${strings.length(resp.body)}")

Iteration

cleat
// Iterate over slice elements
for item in items {
    io.println(item)
}

// Iterate over map keys
for key in scores {
    io.println("${key}: ${scores[key]}")
}

// Iterate over stream chunks
for token in llm.tokens("prompt") {
    io.print(token)
}
Edit this page on GitHub