ADK.State.Delta (ADK v0.0.1-alpha.1)

Copy Markdown View Source

Immutable snapshot + diff for state delta tracking.

Summary

Functions

Apply a delta to a state map.

Compute the difference between two state maps.

Types

t()

@type t() :: %{added: map(), changed: map(), removed: [term()]}

Functions

apply_delta(state, map)

@spec apply_delta(map(), t()) :: map()

Apply a delta to a state map.

Examples

iex> delta = %{added: %{c: 3}, changed: %{a: 10}, removed: [:b]}
iex> ADK.State.Delta.apply_delta(%{a: 1, b: 2}, delta)
%{a: 10, c: 3}

diff(old, new)

@spec diff(map(), map()) :: t()

Compute the difference between two state maps.

Examples

iex> ADK.State.Delta.diff(%{a: 1, b: 2}, %{a: 1, b: 3, c: 4})
%{added: %{c: 4}, changed: %{b: 3}, removed: []}

iex> ADK.State.Delta.diff(%{a: 1, b: 2}, %{a: 1})
%{added: %{}, changed: %{}, removed: [:b]}

iex> ADK.State.Delta.diff(%{}, %{x: 1})
%{added: %{x: 1}, changed: %{}, removed: []}