maca/crdt-replicated-tree/5.0.0

Formerly maca/crdt-replicated-graph. Search finds this package by either name.

CRDTree.Node

This module implements types and functions to build, find, get values from, and compare nodes

type Node a

Node can be either a branch or leaf Node with optional data or a Tombstone representing a removed Node

type Error
= NotFound
| AlreadyApplied
| BadTimestamp

Represents an Error updating a node

Properties

value : Node a -> Maybe a

Return the value of a node

value (node 'a' [0, 1]) == Just 'a'
value (tombstone [0, 1]) == Nothing
timestamp : Node a -> Int

Return the timestamp of a node

timestamp (node 'a' [0, 1]) == 1
path : Node a -> List Int

Return the path of a node

path (node (Just 'a') [0, 1]) == [0, 1]
isDeleted : Node a -> Bool

Return True if the node has been deleted

Traverse

children : Node a -> List (Node a)

Return a list of a nodes' children

descendant : List Int -> Node a -> Maybe (Node a)

Return a Node at a path

Build

init : a -> List Int -> Node a

Build a node

timestamp (init 'a' [0, 1]) == 1
path (init 'a' [0, 1]) == [0, 1]
value (init 'a' [0, 1]) == Just 'a'

Build a root node

timestamp root == 0
path root == []
value root == Nothing
tombstone : List Int -> Node a

Build a tombstone providing timestamp and path

timestamp (tombstone [0, 1]) == 1
path (tombstone [0, 1]) == [0, 1]
value (tombstone [0, 1]) == Nothing

Operations

addAfter : Int -> ( Int, a ) -> Node a -> Result Error (Node a)

Adds after node with timestamp

delete : Int -> Node a -> Result Error (Node a)

Delete a node

Int
-> Node a
-> (Node a -> Result Error (Node a))
-> Result Error (Node a)

Update a node with a successful result