niho / elm-crdt / CRDT.LWWElementSet

An LWWElementSet (or Last-Write-Wins Element Set) is a set where each insert and remove operation is tagged with a timestamp and if an insert and remove occurs concurrently on two separate replicas, the operation with the latest timestamp will take precendence.

LWWElementSet


type LWWElementSet comparable

LWWElementSet state.

empty : LWWElementSet comparable

Constructor that creates a new empty GSet.

insert : comparable -> Time.Posix -> LWWElementSet comparable -> LWWElementSet comparable

Insert a value in the set.

remove : comparable -> Time.Posix -> LWWElementSet comparable -> LWWElementSet comparable

Remove a value from the set.

member : comparable -> LWWElementSet comparable -> Basics.Bool

Determine if a value is in the set.

merge : LWWElementSet comparable -> LWWElementSet comparable -> LWWElementSet comparable

Merge two LWWElementSet states.

fromList : List comparable -> Time.Posix -> LWWElementSet comparable

Convert a list of values into a LWWElementSet.

toList : LWWElementSet comparable -> List comparable

Convert a LWWElementSet to a list of values.

toSet : LWWElementSet comparable -> Set comparable

Convert a LWWElementSet to a Set.

Operations


type Operation comparable
    = Insert comparable Time.Posix
    | Remove comparable Time.Posix

Operations that will modify the state of the set.

apply : Operation comparable -> LWWElementSet comparable -> LWWElementSet comparable

Apply an operation on a LWWElementSet.

patch : List (Operation comparable) -> LWWElementSet comparable -> LWWElementSet comparable

Apply a list of operations (a patch) on a LWWElementSet.

Serialization

encode : LWWElementSet String -> Json.Encode.Value

Encode a LWWElementSet as JSON.

decoder : Json.Decode.Decoder (LWWElementSet String)

Decode a LWWElementSet from JSON.