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
| Method | Signature | Description |
|---|---|---|
.len() | -> int | Number of elements |
.contains(elem) | -> bool | Whether the slice contains the element |
.filter(fn) | -> []T | Keep elements where fn returns true |
.map(fn) | -> []U | Transform each element |
.sum() | -> int | Sum 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
| Method | Signature | Description |
|---|---|---|
.len() | -> int | Number of entries |
.contains(key) | -> bool | Whether the key exists |
.keys() | -> []K | All keys |
.values() | -> []V | All values |
.remove(key) | -> bool | Remove 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) }