View Source FLHook.Dict (FLHook Client v2.1.1)

A module that provides helpers to decode command response and event data.

Summary

Functions

Fetches the field using the specified key from the dict. Optionally allows specification of a type to coerce the param to.

Fetches the field using the specified key from the dict. Optionally allows specification of a type to coerce the value to. Raises when the param is missing or could not be coerced to the given type.

Gets the field using the specified key from the dict.

Fetches multiple fields with the specified keys from the dict. Optionally allows specification of a type to coerce the param to.

Puts multiple fields using the specified keys from the dict into the given struct. Optionally allows specification of a type to coerce the param to.

Converts the dict to a plain map.

Types

@type data() :: %{optional(String.t()) => String.t()}
@type field_type() ::
  :any | :boolean | :duration | :integer | :float | :string | module()
@type key() :: atom() | String.t()
@type t() :: %FLHook.Dict{data: data()}

Functions

Link to this function

fetch(dict, key, type \\ :any)

View Source
@spec fetch(t(), key(), field_type()) ::
  {:ok, any()} | {:error, FLHook.FieldError.t()}

Fetches the field using the specified key from the dict. Optionally allows specification of a type to coerce the param to.

Link to this function

fetch!(dict, key, type \\ :any)

View Source
@spec fetch!(t(), key(), field_type()) :: any() | no_return()

Fetches the field using the specified key from the dict. Optionally allows specification of a type to coerce the value to. Raises when the param is missing or could not be coerced to the given type.

Link to this function

get(dict, key, type \\ :any, default \\ nil)

View Source

Gets the field using the specified key from the dict.

Link to this function

pick(dict, keys_and_types)

View Source (since 0.3.0)
@spec pick(t(), [key()] | [{key(), field_type()}]) ::
  {:ok, %{optional(key()) => any()}} | {:error, FLHook.FieldError.t()}

Fetches multiple fields with the specified keys from the dict. Optionally allows specification of a type to coerce the param to.

Link to this function

pick_into(dict, target, keys_and_types)

View Source (since 0.3.0)
@spec pick_into(t(), module() | struct(), [key()] | [{key(), field_type()}]) ::
  {:ok, struct()} | {:error, FLHook.FieldError.t()}

Puts multiple fields using the specified keys from the dict into the given struct. Optionally allows specification of a type to coerce the param to.

Link to this function

to_map(dict, key_style \\ :string)

View Source (since 0.3.0)
@spec to_map(t(), key_style :: :string | :atom) ::
  %{optional(atom()) => String.t()} | %{optional(String.t()) => String.t()}

Converts the dict to a plain map.