# `Grizzly.ZWave.ZWEnum`
[🔗](https://github.com/smartrent/grizzly/blob/v9.1.4/lib/grizzly/zwave/zw_enum.ex#L1)

A bidirectional map for Z-Wave enumerations.

# `k`

```elixir
@type k() :: atom()
```

# `t`

```elixir
@type t() :: %Grizzly.ZWave.ZWEnum{
  keys: %{optional(atom()) =&gt; non_neg_integer()},
  values: %{optional(non_neg_integer()) =&gt; atom()}
}
```

# `v`

```elixir
@type v() :: non_neg_integer()
```

# `decode`

```elixir
@spec decode(t(), v()) :: {:ok, k()} | :error
```

Alias for `fetch_key/2`.

# `decode!`

```elixir
@spec decode!(t(), v()) :: k()
```

Alias for `fetch_key!/2`.

# `encode`

```elixir
@spec encode(t(), k()) :: {:ok, v()} | :error
```

Alias for `fetch/2`.

# `encode!`

```elixir
@spec encode!(t(), k()) :: v()
```

Alias for `fetch!/2`.

# `equal?`

```elixir
@spec equal?(t(), t()) :: boolean()
```

Checks if two enums are equal.

# `fetch`

```elixir
@spec fetch(t(), k()) :: {:ok, v()} | :error
```

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

# `fetch!`

```elixir
@spec fetch!(t(), k()) :: v()
```

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"

# `fetch_key`

```elixir
@spec fetch_key(t(), v()) :: {:ok, k()} | :error
```

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

# `fetch_key!`

```elixir
@spec fetch_key!(t(), v()) :: k()
```

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

# `get`

```elixir
@spec get(t(), k(), v() | nil) :: v() | nil
```

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"

# `get_key`

```elixir
@spec get_key(t(), v(), k()) :: k() | nil
```

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

# `has_key?`

```elixir
@spec has_key?(t(), k()) :: boolean()
```

Checks if the enum has the given key.

# `keys`

```elixir
@spec keys(t()) :: [k()]
```

Returns a list of all keys in the enum.

## Examples

    iex> enum = new([a: "foo", b: "bar"])
    iex> keys(enum) |> Enum.sort()
    [:a, :b]

# `member?`

```elixir
@spec member?(
  t(),
  {k(), v()}
) :: boolean()
```

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

# `member?`

```elixir
@spec member?(t(), k(), v()) :: boolean()
```

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

# `new`

```elixir
@spec new() :: t()
```

Creates a new empty `ZWEnum`.

# `new`

```elixir
@spec new(Enum.t()) :: t()
```

Creates a new `ZWEnum` from an enumerable of `{key, value}` pairs.

# `new`

```elixir
@spec new(Enum.t(), (term() -&gt; {k(), v()})) :: t()
```

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"]

# `put`

```elixir
@spec put(t(), k(), v()) :: t()
```

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"]

# `size`

```elixir
@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

# `to_list`

```elixir
@spec to_list(t()) :: [{k(), v()}]
```

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"]

# `values`

```elixir
@spec values(t()) :: [v()]
```

Returns a list of all values in the enum.

## Examples

    iex> enum = new([a: "foo", b: "bar"])
    iex> values(enum) |> Enum.sort()
    ["bar", "foo"]

---

*Consult [api-reference.md](api-reference.md) for complete listing*
