A bidirectional map for Z-Wave enumerations.
Summary
Functions
Alias for fetch_key/2.
Alias for fetch_key!/2.
Alias for fetch/2.
Alias for fetch!/2.
Checks if two enums are equal.
Gets the value represented by the given key.
Gets the value represented by the given key, raising if the key is not found.
Gets the key represented by the given value.
Gets the key represented by the given value, raising if the value is not found.
Gets the value for the given key.
Gets the key for the given value.
Checks if the enum has the given key.
Returns a list of all keys in the enum.
Convenience shortcut for member?/3.
Checks if enum contains {key, value} pair.
Creates a new empty ZWEnum.
Creates a new ZWEnum from an enumerable of {key, value} pairs.
Creates a new ZWEnum from an enumerable, transforming each item with the
provided function.
Inserts the given {key, value} pair into the enum.
Returns the number of key-value pairs in the enum.
Converts the enum to a list of {key, value} pairs.
Returns a list of all values in the enum.
Types
@type k() :: atom()
@type t() :: %Grizzly.ZWave.ZWEnum{ keys: %{optional(atom()) => non_neg_integer()}, values: %{optional(non_neg_integer()) => atom()} }
@type v() :: non_neg_integer()
Functions
Alias for fetch_key/2.
Alias for fetch_key!/2.
Alias for fetch/2.
Alias for fetch!/2.
Checks if two enums are equal.
Gets the value represented by the given key.
Examples
iex> enum = new([a: "foo", b: "bar"])
iex> fetch(enum, :a)
{:ok, "foo"}
iex> fetch(enum, :c)
:error
Gets the value represented by the given key, raising if the key is not found.
Examples
iex> enum = new([a: "foo", b: "bar"])
iex> fetch!(enum, :a)
"foo"
Gets the key represented by the given value.
Examples
iex> enum = new([a: "foo", b: "bar"])
iex> fetch_key(enum, "foo")
{:ok, :a}
iex> fetch_key(enum, "baz")
:error
Gets the key represented by the given value, raising if the value is not found.
Examples
iex> enum = new([a: "foo", b: "bar"])
iex> fetch_key!(enum, "foo")
:a
Gets the value for the given key.
Examples
iex> enum = new([a: "foo", b: "bar"])
iex> get(enum, :a)
"foo"
iex> get(enum, :c, "default")
"default"
Gets the key for the given value.
Examples
iex> enum = new([a: "foo", b: "bar"])
iex> get_key(enum, "foo")
:a
iex> get_key(enum, "baz", :default)
:default
Checks if the enum has the given key.
Returns a list of all keys in the enum.
Examples
iex> enum = new([a: "foo", b: "bar"])
iex> keys(enum) |> Enum.sort()
[:a, :b]
Convenience shortcut for member?/3.
Examples
iex> enum = new([a: "foo", b: "bar"])
iex> member?(enum, {:a, "foo"})
true
iex> member?(enum, {:a, "bar"})
false
Checks if enum contains {key, value} pair.
Examples
iex> enum = new([a: "foo", b: "bar"])
iex> member?(enum, :a, "foo")
true
iex> member?(enum, :a, "bar")
false
@spec new() :: t()
Creates a new empty ZWEnum.
Creates a new ZWEnum from an enumerable of {key, value} pairs.
Creates a new ZWEnum from an enumerable, transforming each item with the
provided function.
Examples
iex> enum = new([:a, :b, :c], fn item -> {item, Atom.to_string(item)} end)
iex> to_list(enum) |> Enum.sort()
[a: "a", b: "b", c: "c"]
Inserts the given {key, value} pair into the enum.
Examples
iex> enum = new()
iex> enum = put(enum, :a, "foo")
iex> enum = put(enum, :b, "bar")
iex> to_list(enum) |> Enum.sort()
[a: "foo", b: "bar"]
@spec size(t()) :: non_neg_integer()
Returns the number of key-value pairs in the enum.
Examples
iex> enum = new([a: "foo", b: "bar"])
iex> size(enum)
2
Converts the enum to a list of {key, value} pairs.
Examples
iex> enum = new([a: "foo", b: "bar"])
iex> to_list(enum) |> Enum.sort()
[a: "foo", b: "bar"]
Returns a list of all values in the enum.
Examples
iex> enum = new([a: "foo", b: "bar"])
iex> values(enum) |> Enum.sort()
["bar", "foo"]