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 local = replica_id.new("node-a")
  let assert Ok(node_a) =
    sequence.insert_many(sequence.new(local), 0, ["hello", "world"])

  let assert Ok(node_b) =
    sequence.new(replica_id.new("node-b"))
    |> sequence.insert(0, "!")

  let merged = sequence.merge(node_a, node_b, local)

  sequence.values(merged)
  // -> ["hello", "world", "!"]
}

Modules

ModulePurpose
lattice_sequence/sequenceGeneric list CRDT with stable item IDs, index-based editing, and single-winner move semantics.

Notes

Map composition

lattice_maps/crdt.SequenceSpec creates a Sequence(a) child in a typed map. ORMap supports sparse sequence edits through nested ORMaps. Return the leaf delta from insert_with_delta, delete_with_delta, or move_with_delta, rather than its full updated state.

Sparse receivers need a baseline or eventual delivery of the required history. A later edit alone cannot reconstruct earlier items. Map removal and re-addition starts a fresh generation; superseded generations do not merge into the new sequence.

Outer map pruning does not establish the stability frontier required by sequence.compact. Keep inner compaction separate. LWWMap can also hold a Sequence child, but its assignments select one complete snapshot.

Links

License

MIT

Search Document