View Source Yex.Map (y_ex v0.6.3)

A shareable Map type.

Summary

Functions

delete a key from the map.

get a key from the map.

get(map, key) deprecated

get a key from the map.

set a key-value pair in the map.

Convert to json-compatible format.

Convert to elixir map.

Types

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

Functions

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

delete a key from the map.

Examples

iex> doc = Yex.Doc.new()
iex> map = Yex.Doc.get_map(doc, "map")
iex> Yex.Map.set(map, "plane", ["Hello", "World"])
iex> Yex.Map.delete(map, "plane")
:ok
@spec fetch(t(), binary()) :: {:ok, term()} | :error
@spec fetch(t(), binary()) :: {:ok, term()} | :error

get a key from the map.

Examples

iex> doc = Yex.Doc.new()
iex> map = Yex.Doc.get_map(doc, "map")
iex> Yex.Map.set(map, "plane", ["Hello", "World"])
iex> Yex.Map.fetch(map, "plane")
{:ok, ["Hello", "World"]}
iex> Yex.Map.fetch(map, "not_found")
:error
This function is deprecated. Rename to `fetch/2`.
@spec get(t(), binary()) :: {:ok, term()} | :error

get a key from the map.

Examples

iex> doc = Yex.Doc.new()
iex> map = Yex.Doc.get_map(doc, "map")
iex> Yex.Map.set(map, "plane", ["Hello", "World"])
iex> Yex.Map.get(map, "plane")
{:ok, ["Hello", "World"]}
iex> Yex.Map.get(map, "not_found")
:error
@spec set(t(), term(), term()) :: term()

set a key-value pair in the map.

Examples

iex> doc = Yex.Doc.new()
iex> map = Yex.Doc.get_map(doc, "map")
iex> Yex.Map.set(map, "plane", ["Hello", "World"])
:ok
@spec size(t()) :: integer()
@spec to_json(t()) :: map()

Convert to json-compatible format.

Examples Sync two clients by exchanging the complete document structure

iex> doc = Yex.Doc.new()
iex> map = Yex.Doc.get_map(doc, "map")
iex> Yex.Map.set(map, "array", Yex.ArrayPrelim.from(["Hello", "World"]))
iex> Yex.Map.set(map, "plane", ["Hello", "World"])
iex> assert %{"plane" => ["Hello", "World"], "array" => ["Hello", "World"]} = Yex.Map.to_json(map)
@spec to_map(t()) :: map()

Convert to elixir map.

Examples

iex> doc = Yex.Doc.new()
iex> map = Yex.Doc.get_map(doc, "map")
iex> Yex.Map.set(map, "array", Yex.ArrayPrelim.from(["Hello", "World"]))
iex> Yex.Map.set(map, "plane", ["Hello", "World"])
iex> assert %{"plane" => ["Hello", "World"], "array" => %Yex.Array{}} = Yex.Map.to_map(map)