lattice_sequence
Generic sequence CRDT for Gleam using YATA-style left/right origins.
Use this package when replicas need to edit a shared ordered list concurrently and converge without coordination. lattice_sequence handles arbitrary element types with index-based insert, delete, and move operations; for a text-specific API with grapheme handling, use lattice_text instead.
Installation
gleam add lattice_sequence
Quick example
import lattice_core/replica_id
import lattice_sequence/sequence
pub fn main() {
let node_a =
sequence.new(replica_id.new("node-a"))
|> sequence.insert(0, "hello")
|> sequence.insert(1, "world")
let node_b =
sequence.new(replica_id.new("node-b"))
|> sequence.insert(0, "!")
let merged = sequence.merge(node_a, node_b)
sequence.values(merged)
// -> ["hello", "world", "!"]
}
Modules
| Module | Purpose |
|---|---|
lattice_sequence/sequence | Generic list CRDT with stable item IDs, index-based editing, and single-winner move semantics. |
Notes
- Editing operations:
insert,delete, andmove. - Query helpers:
valuesandlength. - Fallible operations have
try_*_with_deltavariants returningResult; the plain variants assert on invalid indexes. - Delta-state variants (
*_with_delta) return the updated sequence plus a delta that can be merged into other replicas, avoiding full-state sync. - Position anchors:
anchor_at(and thestart_anchor/end_anchorsentinels) create a stable position that survives concurrent edits and merges,resolvemaps it back to a current index, andanchor_to_json/anchor_from_jsonlet anchors travel between replicas (e.g. shared cursors). compactreclaims space from tombstones and origins once a host-supplied stability frontier confirms no in-flight op can reference them, emitting aForwardingMapso anchors and rebased ops keep resolving after the region shrinks.merge,to_json, andfrom_jsonround-trip the full CRDT state; convergence holds on both Erlang and JavaScript targets.
Links
- Project site: https://lattice.tylerbutler.com
- API docs: https://hexdocs.pm/lattice_sequence
- Hex package: https://hex.pm/packages/lattice_sequence
- Repository: https://github.com/tylerbutler/lattice
License
MIT