# `RDF.Diff`
[🔗](https://github.com/rdf-elixir/rdf-ex/blob/v3.0.1/lib/rdf/model/diff.ex#L1)

A data structure for diffs between `RDF.Graph`s and `RDF.Description`s.

A `RDF.Diff` is a struct consisting of two fields `additions` and `deletions`
with `RDF.Graph`s of added and deleted statements.

# `t`

```elixir
@type t() :: %RDF.Diff{additions: RDF.Graph.t(), deletions: RDF.Graph.t()}
```

# `apply`

```elixir
@spec apply(t(), RDF.Description.t() | RDF.Graph.t()) :: RDF.Graph.t()
```

Applies a diff to a `RDF.Graph` or `RDF.Description` by deleting the `deletions` and adding the `additions` of the `diff`.

Deletions of statements which are not present in the given graph or description
are simply ignored.

The result of an application is always a `RDF.Graph`, even if a `RDF.Description`
is given and the additions from the diff are all about the subject of this description.

# `diff`

```elixir
@spec diff(RDF.Description.t() | RDF.Graph.t(), RDF.Description.t() | RDF.Graph.t()) ::
  t()
```

Computes a diff between two `RDF.Graph`s or `RDF.Description`s.

The first argument represents the original and the second argument the new version
of the RDF data to be compared. Any combination of `RDF.Graph`s or
`RDF.Description`s can be passed as first and second argument.

## Examples

    iex> RDF.Diff.diff(
    ...>   RDF.description(EX.S1, init: {EX.S1, EX.p1, [EX.O1, EX.O2]}),
    ...>   RDF.graph([
    ...>    {EX.S1, EX.p1, [EX.O2, EX.O3]},
    ...>    {EX.S2, EX.p2, EX.O4}
    ...>   ]))
    %RDF.Diff{
      additions: RDF.graph([
        {EX.S1, EX.p1, EX.O3},
        {EX.S2, EX.p2, EX.O4}
      ]),
      deletions: RDF.graph({EX.S1, EX.p1, EX.O1})
    }

# `empty?`

```elixir
@spec empty?(t()) :: boolean()
```

Determines if a diff is empty.

A `RDF.Diff` is empty, if its `additions` and `deletions` graphs are empty.

# `invert`
*since 2.1.1* 

```elixir
@spec invert(t()) :: t()
```

Inverts a diff.

This is done by simply swapping the `additions` and `deletions` of the diff.

## Examples

    iex> RDF.Diff.invert(RDF.Diff.new(additions: {EX.S, EX.p, EX.O1}, deletions: {EX.S, EX.p, EX.O2}))
    %RDF.Diff{additions: RDF.graph({EX.S, EX.p, EX.O2}), deletions: RDF.graph({EX.S, EX.p, EX.O1})}

# `new`

```elixir
@spec new(keyword()) :: t()
```

Creates a `RDF.Diff` struct.

Some initial additions and deletions can be provided optionally with the resp.
`additions` and `deletions` keywords. The statements for the additions and
deletions can be provided in any form supported by the `RDF.Graph.new/1` function.

# `union`

```elixir
@spec union(t(), t()) :: t()
```

Returns the union of two diffs.

The diffs are merged by adding up the `additions` and `deletions` of both
diffs respectively.

---

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