differ v0.1.1 Differ.Diffable protocol View Source

Allows to compute diff between terms

Link to this section Summary

Types

List of operations need to be applied

Level of optimization

Defines operator and value that need to be applied with operator

Operators that define how to change data

t()

Diffable term

Functions

Returns a list of tuples that represents an edit script

Optimizes diff operation, to reduce its size

Link to this section Types

List of operations need to be applied

Link to this type

level()

View Source
level() :: 1 | 2 | 3

Level of optimization

Link to this type

operation()

View Source
operation() :: {operator(), term()} | {term(), operator(), term()}

Defines operator and value that need to be applied with operator

Examples

{:del, "s"}
{:skip, 4}
{"key", :ins, "s"}
Link to this type

operator()

View Source
operator() :: :del | :ins | :eq | :diff | :skip | :remove

Operators that define how to change data

  • :del - delete
  • :ins - insert
  • :eq - doesnt change
  • :diff - nested diff that should be applied
  • :skip - skip number of characters or elements
  • :remove - remove number of characters or elements (Non-revertable)

Diffable term

Link to this section Functions

Link to this function

diff(term1, term2)

View Source
diff(t(), t()) :: diff()

Returns a list of tuples that represents an edit script

When implementing this function on a new type, you should always implement this

def diff(term, term), do: [eq: term]
Link to this function

optimize_op(t, operation, level)

View Source
optimize_op(t(), operation(), level()) :: operation() | nil

Optimizes diff operation, to reduce its size

If it returns nil, then operation can be excluded from diff