niho / elm-crdt / CRDT.TwoPSet

A TwoPSet is a replicated set in which removals take precedence over additions. For example, if one replica removes and re-adds an element, while another replica concurrently removes the element, then the merged outcome is that the element is not in the set.

TwoPSet


type TwoPSet comparable

TwoPSet state.

empty : TwoPSet comparable

Constructor that creates a new empty TwoPSet.

insert : comparable -> TwoPSet comparable -> TwoPSet comparable

Insert a value in the set.

remove : comparable -> TwoPSet comparable -> TwoPSet comparable

Remove a value from the set.

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

Determine if a value is in the set.

merge : TwoPSet comparable -> TwoPSet comparable -> TwoPSet comparable

Merge two TwoPSet states.

fromList : List comparable -> TwoPSet comparable

Convert a list of values into a TwoPSet.

toList : TwoPSet comparable -> List comparable

Convert a TwoPSet to a list of values.

toSet : TwoPSet comparable -> Set comparable

Convert a TwoPSet to a Set.

Operations


type Operation comparable
    = Insert comparable
    | Remove comparable

Operations that will modify the state of the set.

apply : Operation comparable -> TwoPSet comparable -> TwoPSet comparable

Apply an operation on a TwoPSet.

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

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

Serialization

encode : (comparable -> Json.Encode.Value) -> TwoPSet comparable -> Json.Encode.Value

Encode a TwoPSet as JSON.

decoder : Json.Decode.Decoder comparable -> Json.Decode.Decoder (TwoPSet comparable)

Decode a TwoPSet from JSON.