View Source Yex.Array (y_ex v0.6.3)

A shareable Array-like type that supports efficient insert/delete of elements at any position.

Summary

Functions

Delete content at the specified index.

Delete contents in the specified range.

Get content at the specified index.

get(array, index) deprecated

Get content at the specified index.

Insert content at the specified index.

Returns the length of the array

Push content to the end of the array.

Convert to json-compatible format.

Returns as list

Unshift content to the beginning of the array.

Types

@type t() :: %Yex.Array{doc: reference(), reference: reference()}

Functions

@spec delete(t(), integer()) :: :ok

Delete content at the specified index.

Link to this function

delete_range(array, index, length)

View Source
@spec delete_range(t(), integer(), integer()) :: :ok

Delete contents in the specified range.

@spec fetch(t(), integer()) :: {:ok, term()} | :error

Get content at the specified index.

@spec fetch!(t(), integer()) :: term()
This function is deprecated. Rename to `fetch/2`.
@spec get(t(), integer()) :: {:ok, term()} | :error

Get content at the specified index.

Examples Sync two clients by exchanging the complete document structure

iex> doc = Yex.Doc.new()
iex> array = Yex.Doc.get_array(doc, "array")
iex> Yex.Array.push(array, "Hello")
iex> Yex.Array.get(array, 0)
{:ok, "Hello"}
Link to this function

insert(array, index, content)

View Source

Insert content at the specified index.

Returns the length of the array

Examples Sync two clients by exchanging the complete document structure

iex> doc = Yex.Doc.new()
iex> array = Yex.Doc.get_array(doc, "array")
iex> Yex.Array.push(array, "Hello")
iex> Yex.Array.push(array, "World")
iex> Yex.Array.length(array)
2

Push content to the end of the array.

@spec to_json(t()) :: term()

Convert to json-compatible format.

Examples Sync two clients by exchanging the complete document structure

iex> doc = Yex.Doc.new()
iex> array = Yex.Doc.get_array(doc, "array")
iex> Yex.Array.push(array, "Hello")
iex> Yex.Array.push(array, "World")
iex> Yex.Array.to_json(array)
["Hello", "World"]

Returns as list

Examples Sync two clients by exchanging the complete document structure

iex> doc = Yex.Doc.new()
iex> array = Yex.Doc.get_array(doc, "array")
iex> Yex.Array.push(array, "Hello")
iex> Yex.Array.push(array, "World")
iex> Yex.Array.push(array, Yex.ArrayPrelim.from([1, 2]))
iex> ["Hello", "World", %Yex.Array{}] = Yex.Array.to_list(array)

Unshift content to the beginning of the array.