View Source Audit.Delta (Audit v0.1.1)

Simple difference engine

Link to this section Summary

Functions

Identifies boring values

Takes delta between two items

Link to this section Types

@type delta() :: {:update, any(), any()} | {:delete, any()} | {:add, any()}
@type delta_spec() :: [{path(), delta()}]
@type path() :: list()

Link to this section Functions

@spec boring?(any()) :: boolean()

Identifies boring values

examples

Examples

iex> Delta.boring?(false) true

iex> Delta.boring?("") true

iex> Delta.boring?(nil) true

iex> Delta.boring?([]) true

iex> Delta.boring?(0) true

iex> Delta.boring?(0.0) true

iex> Delta.boring?([false, "", nil, [], 0, 0.0]) true

iex> Delta.boring?(%{a: false, b: "", c: nil, d: [], e: 0, f: 0.0}) true

iex> Delta.boring?({false, "", nil, [], 0, 0.0}) true

iex> Delta.boring?(%{foo: ""}) true

iex> Delta.boring?(%{foo: "185 Berry St"}) false

iex> Delta.boring?("boring") false

@spec delta(any(), any()) :: delta_spec()

Takes delta between two items

examples

Examples

iex> Delta.delta(%{ a: 1, b: 2, c: 3}, %{ a: 2, b: 2, d: 4 })
[
  {[:a], {:update, 1, 2}},
  {[:c], {:delete, 3}},
  {[:d], {:add, 4}}
]

iex> Delta.delta([:a, :b, :c], [:a, :d, :c])
[
  {[1], {:update, :b, :d}}
]

iex> Delta.delta({:a, :b, :c}, {:a, :d, :c})
[
  {[1], {:update, :b, :d}}
]

iex> Delta.delta(:apple, :orange)
[
  {[], {:update, :apple, :orange}}
]

iex> Delta.delta(:apple, :apple)
[]

iex> Delta.delta("", :orange)
[
  {[], {:add, :orange}}
]

iex> Delta.delta(:apple, "")
[
  {[], {:delete, :apple}}
]

iex> Delta.delta({:a, :b, :c}, {:a, :d, :c})
[
  {[1], {:update, :b, :d}}
]

iex> Delta.delta({:a, :b, :c}, {:a, :b, :c})
[]

iex> Delta.delta({:a, :b, :c}, {:a, :b, :c, :d})
[
  {[], {:update, {:a, :b, :c}, {:a, :b, :c, :d}}}
]

iex> Delta.delta([:a, :b, :c], [:a, :d, :c])
[
  {[1], {:update, :b, :d}}
]

iex> Delta.delta([:a, :b, :c], [:a, :b, :c])
[]

iex> Delta.delta([:a, :b, :c], [:a, :b, :c, :d])
[
  {[], {:update, [:a, :b, :c], [:a, :b, :c, :d]}}
]

iex> Delta.delta(%{ a: 1, b: 2, c: 3}, %{ a: 2, b: 2, d: 4 })
[
  {[:a], {:update, 1, 2}},
  {[:c], {:delete, 3}},
  {[:d], {:add, 4}}
]
@spec delta_map(path(), map(), map()) :: delta_spec()
Link to this function

delta_struct(path, a, b)

View Source
@spec delta_struct(path(), struct(), struct()) :: delta_spec()