<!-- Sema documentation — std.collections
     Sema is a new AI-native, neurosymbolic programming language most models
     have not been trained on. Full corpus: https://sema.49.12.246.95.sslip.io/llms-full.txt
     Install language support: https://sema.49.12.246.95.sslip.io/install-skill/ -->

# std.collections

> Small pure list and string helpers used across the Sema standard library — joins, stable rounding, and order-preserving de-duplication.

`std.collections` is the standard library's own toolbox of **small, pure helpers**
for lists and strings. Every function here has an empty effect row `!{}` — they
compute and nothing else — which is why the rest of the stdlib (and `document` in
particular) builds on them.

```sema
from std.collections import join_str, join_ints, join_floats, dedup_ints, r6
```

## Why it exists

These are the little utilities that would otherwise be re-inlined in every module:
joining a list into a delimited string, rounding to a stable number of decimals
for display, de-duplicating while preserving order. Centralizing them keeps the
rest of the stdlib compact and gives your own deterministic core the same
building blocks. For the primitive collection types (`list`, `dict`, `tuple`)
themselves, see [Types](/language/types/).

## String joins

`join_str` joins a list of strings with a separator. `join_ints` and
`join_floats` stringify first (floats via `r6`, below):

```sema
join_str(["a", "b", "c"], ", ")     # "a, b, c"
join_ints([1, 2, 3], "-")           # "1-2-3"
join_floats([0.1, 0.25], " | ")     # "0.1 | 0.25"
```

## Stable numeric display

`r6` rounds to six decimal places, so numeric output is stable and comparable
across runs (no long floating-point tails):

```sema
r6(0.12345678)     # 0.123457
```

`join_floats` uses `r6` internally, so a list of floats renders consistently.

## Order-preserving de-duplication

`dedup_ints` removes duplicate integers while keeping first-seen order — useful
for collapsing a list of ids without sorting it:

```sema
dedup_ints([3, 1, 3, 2, 1])     # [3, 1, 2]
```

:::note[The pure-core discipline]
Every helper here carries `!{}`. Keeping utility code in the deterministic,
invoke-free core means it is trivially testable and safe to call from anywhere —
including inside a `simulate def` contract or a metered scope.
:::

:::tip[Semantic de-duplication]
`dedup_ints` is exact equality over ints. When you need to collapse *near*
duplicates — paraphrases, restatements — reach for the neurosymbolic
`semantic.dedup` operation instead, which uses calibrated similarity.
:::

See the full signature list in the generated
[std.collections API reference](/reference/stdlib-api/collections/).
