soma.cell

Collections builtins

18 builtins of Soma 3.2.4 in the category Collections, with their exact signatures, as soma describe --builtins --json prints them.

list

list(items...) -> List

Build a list of the arguments; list(list(1, 2), 3) is [[1, 2], 3]. Use push(xs, x) to append.

deterministic · replay: pure

Used in verified programs:

map

map(key, value, ...) -> Map | list |> map(x => expr) -> List

Build a map from key-value pairs (even arg count), or — with a lambda — transform each list element.

deterministic · replay: pure

Used in verified programs:

push

push(list: List, items...) -> List

Return a new list with the items appended (the original is unchanged).

deterministic · replay: pure

Used in verified programs:

nth

nth(list: List, i: Int) -> Any

Element at index i, or () when out of bounds.

deterministic · replay: pure

reverse

reverse(list: List) -> List

Return the list in reverse order.

deterministic · replay: pure

Used in verified programs:

range

range(start: Int, end: Int, step?: Int) -> List<Int>

Integers from start toward end (exclusive); bounds and step are 64-bit Ints. A negative step counts down; zero raises kind range. Direct for-loops do not materialize the list, including stepped ranges.

deterministic · replay: pure

Used in verified programs:

sort

sort(list: List, order?: "desc") -> List

Sort scalars ascending (or "desc"); errors on incomparable element types.

deterministic · replay: pure

Used in verified programs:

flatten

flatten(list: List) -> List

Flatten one level of nested lists.

deterministic · replay: pure

Used in verified programs:

  • records/bst, line 54: return list(_walk(t.left), list(t.v), _walk(t.right)) |> flatten()
  • records/family_tree, line 56: out = list(out, _collect(c, cur + 1, target)) |> flatten()

zip

zip(a: List, b: List) -> List<{left, right}>

Pair elements positionally; stops at the shorter list.

deterministic · replay: pure

Used in verified programs:

  • math/vector_ops, line 21: let prods = zip(a, b) |> map(p => p.left * p.right)

enumerate

enumerate(list: List) -> List<{index, value}>

Attach a 0-based index to each element.

deterministic · replay: pure

Used in verified programs:

with

with(m: Map, key, value, ...) -> Map | with(list: List, i: Int, value) -> List

Copy of the map with every key-value pair inserted, or copy of the list with element i replaced. An incomplete pair raises kind type; large Int map keys are stringified, while list indices must fit signed 64 bits.

deterministic · replay: pure

Used in verified programs:

without

without(m: Map, keys...) -> Map

Return a copy of the map with the given keys removed.

deterministic · replay: pure

Used in verified programs:

merge

merge(a: Map, b: Map, ...) -> Map

Copy of a with all entries of b (and of each later map) inserted — a later map wins on conflict.

deterministic · replay: pure

Used in verified programs:

join

join(list: List, sep: String) -> String | join(left: List, right: List, key) -> List

Join list elements into a string — or, with two lists, an inner data join on key.

deterministic · replay: pure

Used in verified programs:

slice

slice(xs: List|String, start: Int, end?: Int) -> List|String

Sub-list / substring, end exclusive; negative indexes count from the end (slice(xs, -2) = last two). Clamped, never raises.

deterministic · replay: pure

keys

keys(m: Map) -> List<String>

Keys of a map VALUE, in insertion order. (Memory slots: slot.keys().)

deterministic · replay: pure

values

values(m: Map) -> List

Values of a map VALUE, in insertion order. (Memory slots: slot.values().)

deterministic · replay: pure

entries

entries(m: Map) -> List<{key, value}>

Key/value records of a map VALUE: for e in entries(m) { e.key e.value }.

deterministic · replay: pure