CRDT v0.2.0 CRDT.LWWRegister View Source

A last-write wins register

Link to this section Summary

Types

t()

An LWWRegister with a local vector clock and remote values

Functions

Incorporate a remote LWWRegister

Initialize a new LWWRegister

Set the value of the LWWRegister

Link to this section Types

Link to this type t() View Source
t() :: %CRDT.LWWRegister{id: id(), ts: ts(), value: value(), vec: vec()}

An LWWRegister with a local vector clock and remote values

Link to this section Functions

Link to this function incorporate(r, ts, val) View Source
incorporate(t(), ts(), value()) :: t()

Incorporate a remote LWWRegister.

iex> r = LWWRegister.init()
iex> r2 = LWWRegister.init() |> LWWRegister.set(2)
iex> r
...> |> LWWRegister.incorporate(r2.ts, r2.value)
...> |> Map.get(:value)
2
Link to this function init(val \\ nil) View Source
init(value()) :: t()

Initialize a new LWWRegister.

Accepts an initial value, which defaults to nil.

iex> LWWRegister.init() |> Map.get(:value)
nil

iex> LWWRegister.init("test") |> Map.get(:value)
"test"
Link to this function set(r, val) View Source
set(t(), value()) :: t()

Set the value of the LWWRegister.

iex> LWWRegister.init(1) |> LWWRegister.set(2) |> Map.get(:value)
2