View Source PieceTable.Change (piece_table v0.1.2)

A struct to hold changes in the PieceTable

usage

Usage

iex> table = PieceTable.Change.new!(:ins, "test", 3)
%PieceTable.Change{change: :ins, position: 3, text: "test"}

Link to this section Summary

Functions

Inverts the operation of a PieceTable.Change struct.

Inverts the operation of a PieceTable.Change struct.

Creates a new PieceTable.Change struct. This is intended the only method to build it.

Creates a new PieceTable.Change struct. This is intended the only method to build it.

Link to this section Types

@type t() :: %PieceTable.Change{change: atom(), position: integer(), text: String.t()}

Link to this section Functions

@spec invert(t()) :: {:ok, t()} | {:error, any()}

Inverts the operation of a PieceTable.Change struct.

parameters

Parameters

  • chg (PieceTable.Change.t()): The change to invert

returns

Returns

  • {:ok, %PieceTable.Change{}}
  • {:error, any}

examples

Examples

iex> PieceTable.Change.invert(%PieceTable.Change{change: :ins, text: "random", position: 5})
{:ok, %PieceTable.Change{change: :del, text: "random", position: 5}}
@spec invert!(t()) :: t()

Inverts the operation of a PieceTable.Change struct.

parameters

Parameters

  • chg (PieceTable.Change.t()): The change to invert

returns

Returns

  • %PieceTable.Change{}

examples

Examples

iex> PieceTable.Change.invert(%PieceTable.Change{change: :ins, text: "random", position: 5})
{:ok, %PieceTable.Change{change: :del, text: "random", position: 5}}
Link to this function

new(change, text, position)

View Source
@spec new(atom(), String.t(), integer()) ::
  {:ok, t()} | {:error, {atom(), String.t(), integer()}}

Creates a new PieceTable.Change struct. This is intended the only method to build it.

parameters

Parameters

  • change (atom()): The operation it represents [:ins | :del]

  • text (String.t()): The text to edit
  • position (integer()): The position at which the edit occurs

returns

Returns

  • {:ok, %PieceTable.Change{}}
  • {:error, {:wrong, "edit", -1}}

examples

Examples

iex> PieceTable.Change.new(:ins, "test", 4)
{:ok, %PieceTable.Change{change: :ins, text: "test", position: 4}}
Link to this function

new!(change, text, position)

View Source
@spec new!(atom(), String.t(), integer()) :: t()

Creates a new PieceTable.Change struct. This is intended the only method to build it.

parameters

Parameters

  • change (atom()): The operation it represents [:ins | :del]

  • text (String.t()): The text to edit
  • position (integer()): The position at which the edit occurs

returns

Returns

  • %PieceTable.Change{}

examples

Examples

iex> PieceTable.Change.new!(:ins, "test", 4)
%PieceTable.Change{change: :ins, text: "test", position: 4}