View Source Yex.Array (y_ex v0.7.1)
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.
Insert content at the specified index.
Insert contents at the specified index.
Returns the length of the array
Moves element found at source
index into target
index position. Both indexes refer to a current state of the document.
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
Functions
Delete content at the specified index.
Delete contents in the specified range.
Get content at the specified index.
Examples pushes a string then fetches it back
iex> doc = Yex.Doc.new()
iex> array = Yex.Doc.get_array(doc, "array")
iex> Yex.Array.push(array, "Hello")
iex> Yex.Array.fetch(array, 0)
{:ok, "Hello"}
Insert content at the specified index.
Insert contents at the specified index.
Examples
iex> doc = Yex.Doc.new()
iex> array = Yex.Doc.get_array(doc, "array")
iex> Yex.Array.insert_list(array, 0, [1,2,3,4,5])
iex> Yex.Array.to_json(array)
[1, 2, 3, 4, 5]
Returns the length of the array
Examples adds a few items to an array and returns its length
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
Moves element found at source
index into target
index position. Both indexes refer to a current state of the document.
Examples pushes a string then fetches it back
iex> doc = Yex.Doc.new()
iex> array = Yex.Doc.get_array(doc, "array")
iex> Yex.Array.push(array, Yex.ArrayPrelim.from([1, 2]))
iex> Yex.Array.push(array, Yex.ArrayPrelim.from([3, 4]))
iex> :ok = Yex.Array.move_to(array, 0, 2)
iex> Yex.Array.to_json(array)
[[3, 4], [1, 2]]
Push content to the end of the array.
Convert to json-compatible format.
Examples adds a few items to an array and returns as Elixir List
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 adds a few items to an array, then gets them back as Elixir List
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.