View Source Yex.Map (y_ex v0.7.1)
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. ## Examples
set a key-value pair in the map.
Convert to json-compatible format.
Convert to elixir map.
Types
Functions
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`.
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
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
Convert to json-compatible format.
Examples shows a map being created incrementally then returned
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)
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)