View Source K8s.Resource.NamedList (k8s v1.1.1)

Provides an accessor to a list of maps whereas each element in the list has a key named "name". The name should be unique within the list and therefore defining the element.

Link to this section Summary

Functions

Provides an accessor to a list of maps whereas each element in the list has a key named "name". If no such element exists within the given list, get_in() will return nil while updating will create an empty element with the given name.

Provides an accessor to a list of maps whereas each element in the list has a key named "name". If no such element exists within the given list, an exception is raised.

Link to this section Functions

Specs

access(binary()) :: Access.access_fun(data :: list(), get_value :: term())

Provides an accessor to a list of maps whereas each element in the list has a key named "name". If no such element exists within the given list, get_in() will return nil while updating will create an empty element with the given name.

examples

Examples

iex> get_in([%{"name" => "key1", "value" => "value1"}, %{"name" => "key2", "value" => "value2"}], [K8s.Resource.NamedList.access("key2"), "value"]) "value2"

iex> get_in([%{"name" => "key1", "value" => "value1"}, %{"name" => "key2", "value" => "value2"}], [K8s.Resource.NamedList.access("key2")]) %{"name" => "key2", "value" => "value2"}

iex> get_in([%{"name" => "key1", "value" => "value1"}], [K8s.Resource.NamedList.access("missing-key"), "value"]) nil

iex> get_in([%{"name" => "key1", "value" => "value1"}], [K8s.Resource.NamedList.access("missing-key")]) nil

iex> put_in([%{"name" => "key1", "value" => "value1"}, %{"name" => "key2", "value" => "value2"}], [K8s.Resource.NamedList.access("key1"), "value"], "value_new") [%{"name" => "key1", "value" => "value_new"}, %{"name" => "key2", "value" => "value2"}]

iex> put_in([%{"name" => "key1", "value" => "value1"}], [K8s.Resource.NamedList.access("missing-key"), "value"], "value_new") [%{"name" => "missing-key", "value" => "value_new"}, %{"name" => "key1", "value" => "value1"}]

iex> pop_in([%{"name" => "key1", "value" => "value1"}, %{"name" => "key2", "value" => "value2"}], [K8s.Resource.NamedList.access("key1"), "value"]) {"value1", [%{"name" => "key1"}, %{"name" => "key2", "value" => "value2"}]}

iex> pop_in([%{"name" => "key1", "value" => "value1"}], [K8s.Resource.NamedList.access("missing-key"), "value"]) {nil, [%{"name" => "missing-key"}, %{"name" => "key1", "value" => "value1"}]}

iex> pop_in([%{"name" => "key1", "value" => "value1"}], [K8s.Resource.NamedList.access("missing-key")]) {%{"name" => "missing-key"}, [%{"name" => "key1", "value" => "value1"}]}

Specs

access!(binary()) :: Access.access_fun(data :: list(), get_value :: term())

Provides an accessor to a list of maps whereas each element in the list has a key named "name". If no such element exists within the given list, an exception is raised.

examples

Examples

iex> get_in([%{"name" => "key1", "value" => "value1"}, %{"name" => "key2", "value" => "value2"}], [K8s.Resource.NamedList.access!("key2"), "value"]) "value2"

iex> get_in([%{"name" => "key1", "value" => "value1"}, %{"name" => "key2", "value" => "value2"}], [K8s.Resource.NamedList.access!("key2")]) %{"name" => "key2", "value" => "value2"}

iex> get_in([%{"name" => "key1", "value" => "value1"}], [K8s.Resource.NamedList.access!("missing-key"), "value"]) ** (ArgumentError) There is not item with name missing-key in the given named list.

iex> get_in([%{"name" => "key1", "value" => "value1"}], [K8s.Resource.NamedList.access!("missing-key")]) ** (ArgumentError) There is not item with name missing-key in the given named list.

iex> put_in([%{"name" => "key1", "value" => "value1"}, %{"name" => "key2", "value" => "value2"}], [K8s.Resource.NamedList.access!("key1"), "value"], "value_new") [%{"name" => "key1", "value" => "value_new"}, %{"name" => "key2", "value" => "value2"}]

iex> put_in([%{"name" => "key1", "value" => "value1"}], [K8s.Resource.NamedList.access!("missing-key"), "value"], "value_new") ** (ArgumentError) There is not item with name missing-key in the given named list.

iex> pop_in([%{"name" => "key1", "value" => "value1"}, %{"name" => "key2", "value" => "value2"}], [K8s.Resource.NamedList.access!("key1"), "value"]) {"value1", [%{"name" => "key1"}, %{"name" => "key2", "value" => "value2"}]}

iex> pop_in([%{"name" => "key1", "value" => "value1"}], [K8s.Resource.NamedList.access!("missing-key"), "value"]) ** (ArgumentError) There is not item with name missing-key in the given named list.

iex> pop_in([%{"name" => "key1", "value" => "value1"}], [K8s.Resource.NamedList.access!("missing-key")]) ** (ArgumentError) There is not item with name missing-key in the given named list.