niho/elm-crdt/1.0.0

CRDT.GCounter

A GCounter (or Grow-only Counter) is a replicated counter that is guaranteed to always converge to a single value, despite concurrent updates. A GCounter only supports incrementing the counter. If you need a counter that can also be decremented, you should use a PNCounter instead.

GCounter

type alias Replica =
String

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

GCounter state

Constructor that creates a new GCounter with the value zero.

increment : Replica -> GCounter -> GCounter

Increment the GCounter (+1).

value : GCounter -> Int

Get the current value of the GCounter.

Merge two GCounter states.

Operations

= Increment Replica

Operations that will modify the state of the counter. A GCounter only supports a single operation (Increment).

Apply an operation on a GCounter.

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

Serialization

encode : GCounter -> Value

Encode a GCounter as JSON.

decoder : Decoder GCounter

Decode a GCounter from JSON.