niho / elm-crdt / CRDT.PNCounter

A PNCounter (or Positive-Negative Counter) is a replicated counter that can be both incremented and decremented.

PNCounter


type alias Replica =
CRDT.GCounter.Replica

Each replica that modifies the counter is represented by a unique string ID.


type PNCounter

PNCounter state

zero : PNCounter

Constructor that creates a new PNCounter with the value zero.

increment : Replica -> PNCounter -> PNCounter

Increment the PNCounter.

decrement : Replica -> PNCounter -> PNCounter

Decrement the PNCounter.

value : PNCounter -> Basics.Int

Get the current value of the PNCounter.

merge : PNCounter -> PNCounter -> PNCounter

Merge two PNCounter states.

Operations


type Operation
    = Increment Replica
    | Decrement Replica

Operations that will modify the state of the counter.

apply : Operation -> PNCounter -> PNCounter

Apply an operation on a PNCounter.

patch : List Operation -> PNCounter -> PNCounter

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

Serialization

encode : PNCounter -> Json.Encode.Value

Encode a PNCounter as JSON.

decoder : Json.Decode.Decoder PNCounter

Decode a PNCounter from JSON.