# `ADK.State.Delta`
[🔗](https://github.com/zeroasterisk/adk-elixir/blob/main/lib/adk/state/delta.ex#L1)

Immutable snapshot + diff for state delta tracking.

# `t`

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

# `apply_delta`

```elixir
@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`

```elixir
@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: []}

---

*Consult [api-reference.md](api-reference.md) for complete listing*
