differ v0.1.1 Differ.Patchable protocol View Source

Allows to apply diff to a term

Link to this section Summary

Functions

Performs operation op on term

Returns the opposite of operation

Link to this section Types

Link to this section Functions

Link to this function

explain(old_val, op, acc, cb)

View Source
Link to this function

perform(old_val, op, new_val)

View Source
perform(t(), Differ.Diffable.operation(), tuple()) ::
  {:ok, {term(), any()}} | {:error, reason()} | {:conflict, any()}
perform(t(), {term(), :diff, Differ.Diffable.diff()}, tuple()) ::
  {:diff, Differ.Diffable.diff(), term(), {term(), :ins}}

Performs operation op on term

First argument is original term. Second is operation, that get matched against functions in implementations. Third is a tuple, where first item should be result of the operation, and second is anything else.

Function should return tuple with :ok atom and tuple {result, anything}

Link to this function

revert_op(val, op)

View Source
revert_op(t(), Differ.Diffable.operation()) ::
  {:ok, Differ.Diffable.operation()} | {:error, reason()}

Returns the opposite of operation

If operation is not revertable, should return {:error, reason}

Examples

iex> Differ.diffable.revert("", {:del, "ttypo"})
{:ok, {:ins, "ttypo"}}

iex> Differ.diffable.revert("", {:remove, 10})
{:error, "Operation is not revertable"}