CRDT v0.2.0 CRDT.GCounter View Source
A grow-only counter
Link to this section Summary
Functions
Incorporate a remote site value into the GCounter
Increment the local site value of the GCounter
Initialize a new GCounter
Get the value of the GCounter
Link to this section Types
Link to this type
t()
View Source
t() :: %CRDT.GCounter{id: id(), values: %{optional(id()) => value()}}
A GCounter with an ID and map of site values
Link to this section Functions
Incorporate a remote site value into the GCounter.
iex> g = GCounter.init(1)
iex> g2 = GCounter.init(2)
iex> g
...> |> GCounter.incorporate(g2.id, GCounter.value(g2))
...> |> GCounter.value
3
Increment the local site value of the GCounter.
iex> GCounter.init()
...> |> GCounter.increment
...> |> GCounter.value
1
Initialize a new GCounter.
Accepts an initial value, which defaults to 0.
iex> GCounter.init() |> GCounter.value
0
iex> GCounter.init(1) |> GCounter.value
1
Get the value of the GCounter.
iex> g = GCounter.init
iex> g = Enum.reduce(1..100, g, fn (_, g) ->
...> GCounter.increment(g)
...> end)
iex> GCounter.value(g)
100