niho/elm-crdt/1.0.0

CRDT.PNCounter

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

PNCounter

type alias Replica =
Replica

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

PNCounter state

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 -> Int

Get the current value of the PNCounter.

Merge two PNCounter states.

Operations

= Increment Replica
| Decrement Replica

Operations that will modify the state of the counter.

Apply an operation on a PNCounter.

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

Serialization

encode : PNCounter -> Value

Encode a PNCounter as JSON.

decoder : Decoder PNCounter

Decode a PNCounter from JSON.