Skip to content

v0.1.0: Initial release

Latest

Choose a tag to compare

@bruce bruce released this 09 Nov 09:09
dfffadc

Initial release.

Provides Diffident.explain/2, returning a serializable diff (a list of tuples) comparing two Elixir values.

left = %{
  user: [
    %{id: 1, name: "Alice"},
    %{id: 2, name: "Bob"}
  ],
  meta: {:ok, %{count: 2}}
}

right = %{
  user: [
    %{id: 1, name: "Alice"},
    %{id: 2, name: "Robert"},
    %{id: 3, name: "Carol"}
  ],
  meta: {:ok, %{count: 3}}
}

Diffident.explain(left, right)
# Returns:
#   [
#     {:changed, [:user, {Access, :at, [1]}, :name], "Bob", "Robert"},
#     {:added, [:user, {Access, :at, [2]}], %{id: 3, name: "Carol"}},
#     {:changed, [:meta, {Access, :elem, [1]}, :count], 2, 3}
#  ]

See also:

  • Diffident.get_in/2 - Use the path returned in a diff tuple to get a value
  • Diffident.put_in/3 - Use the path returned in a diff tuple to put a value
  • Diffident.to_access_compatible/1 - Convert the path returned in a diff tuple to one that will work with the Access behavior
    • This is used by Diffident.get_in/2 and Diffident.put_in/3 to convert the serializable MFAs to Access function calls, e.g.: {Access, :elem, [1]} becomes Access.elem(1).