OT v0.1.0 OT.Text.Application

The application of a text operation to a piece of text.

Summary

Types

The result of an apply/2 function call, representing either success or error in application of an operation

Functions

Apply an operation to a piece of text

Same as apply/2, but raises if the application fails

Types

apply_result()
apply_result ::
  {:ok, OT.Text.datum} |
  {:error, :delete_mismatch | :retain_too_long}

The result of an apply/2 function call, representing either success or error in application of an operation

Functions

Apply an operation to a piece of text.

Given a piece of text and an operation, iterate over each component in the operation and apply it to the given text. If the operation is valid, the function will return {:ok, new_state} where new_state is the text with the operation applied to it. If the operation is invalid, an {:error, atom} tuple will be returned.

Examples

iex> OT.Text.Application.apply("Foo", [3, %{i: " Bar"}])
{:ok, "Foo Bar"}

iex> OT.Text.Application.apply("Foo", [%{d: "Foos"}])
{:error, :delete_mismatch}

Errors

  • :delete_mismatch A delete component did not match the text it would have deleted in the text
  • :retain_too_long A retain component skipped past the end of the text
apply!(text, op)

Same as apply/2, but raises if the application fails.