# `ExUtils.Maps`
[🔗](https://github.com/sheharyarn/ex_utils/blob/main/lib/ex_utils/maps.ex#L1)

Elixir Utility methods for the `Map` module

# `atomize_keys`

> This function is deprecated. Use ExUtils.Maps.atomize_keys/3 instead.

# `atomize_keys`

```elixir
@spec atomize_keys(map(), :all | [atom()], Keyword.t()) :: map()
```

Atomize the given keys of a map.

Passed keys must be a list of atoms or `:all`. Using a list of atoms is
the recommended way. If you use `:all`, you must be careful to avoid
calling it on external or unknown data, which can grow the Erlang Atom table,
and may even cause it to overload.

## Options

- `:deep` - Perform conversion for keys in nested maps. Defaults to `false`.
- `:drop` - Drop unconverted keys. Defaults to `false`.

Original, converted string keys are always dropped.

## Examples

```elixir
iex> map = %{"a" => 1, "b" => %{"c" => 3, "d" => 4}}
iex> ExUtils.Maps.atomize_keys(map, [:a, :b])
%{a: 1, b: %{"c" => 3, "d" => 4}}
iex> ExUtils.Maps.atomize_keys(map, [:a, :b], deep: true)
%{a: 1, b: %{"c" => 3, "d" => 4}}
iex> ExUtils.Maps.atomize_keys(map, [:a, :b, :d], deep: true)
%{a: 1, b: %{"c" => 3, d: 4}}
iex> ExUtils.Maps.atomize_keys(map, [:a], drop: true)
%{a: 1}
iex> ExUtils.Maps.atomize_keys(map, :all, deep: true)
%{a: 1, b: %{c: 3, d: 4}}
```

# `drop_blank_values`

```elixir
@spec drop_blank_values(map(), Keyword.t()) :: map()
```

Removes all keys with blank values.

## Options

- `:blanks` - Values considered blank. Defaults to `[nil, "", []]`.

## Examples

```elixir
iex> ExUtils.Maps.drop_blank_values(%{a: 123, b: nil, c: "", d: [], e: false})
%{a: 123, e: false}

iex> ExUtils.Maps.drop_blank_values(%{count: 0, active: false}, blanks: [nil, 0])
%{active: false}
```

# `flatten`

```elixir
@spec flatten(map(), Keyword.t()) ::
  %{required(String.t()) =&gt; any()} | %{required([any()]) =&gt; any()}
```

Flattens nested maps and lists into a map keyed by their access paths.

Structs and empty maps or lists are preserved as values.

## Options

- `:key_format` - Format used for flattened keys. Use `:string` for
  dot-separated string or `:path` for lists containing the original path
  segments. Defaults to `:string`.

## Examples

```elixir
iex> ExUtils.Maps.flatten(%{user: %{name: "Ada", settings: %{theme: "dark"}}})
%{"user.name" => "Ada", "user.settings.theme" => "dark"}

iex> ExUtils.Maps.flatten(%{profiles: [%{platform: "github", username: "ada"}]})
%{"profiles.0.platform" => "github", "profiles.0.username" => "ada"}

iex> ExUtils.Maps.flatten(%{user: %{name: "Ada"}}, key_format: :path)
%{[:user, :name] => "Ada"}
```

# `from_struct`

```elixir
@spec from_struct(map(), Keyword.t()) :: map()
```

Converts a struct/map to plain map.

## Options

- `:deep` - recursively converts nested structs when `true`. Defaults to `true`.

Date, time, and date-time structs are preserved.

## Examples

```elixir
iex> ExUtils.Maps.from_struct(1..3)
%{first: 1, last: 3, step: 1}

iex> date = ~D[2026-10-04]
iex> ExUtils.Maps.from_struct(date)
~D[2026-10-04]
```

# `maybe_put`

```elixir
@spec maybe_put(map(), any(), any(), Keyword.t()) :: map()
```

Puts a key-value pair into a map when the value is not blank.

## Options

- `:blanks` - Values considered blank. Defaults to `[nil, "", []]`.

## Examples

```elixir
iex> ExUtils.Maps.maybe_put(%{}, :name, "John")
%{name: "John"}

iex> ExUtils.Maps.maybe_put(%{name: "Mary"}, :name, "John")
%{name: "John"}

iex> ExUtils.Maps.maybe_put(%{name: "John"}, :name, nil)
%{name: "John"}

iex> ExUtils.Maps.maybe_put(%{}, :count, 0, blanks: [nil, 0])
%{}
```

# `stringify_keys`

```elixir
@spec stringify_keys(map(), :all | [atom()], Keyword.t()) :: map()
```

Converts the given map keys to strings.

Passed keys must be a list of atoms or `:all`.

## Options

- `:deep` - Perform conversion for keys in nested maps. Defaults to `false`.
- `:drop` - Drop unconverted keys. Defaults to `false`.

Original, converted atom keys are always dropped.

## Examples

```elixir
iex> map = %{a: 1, b: %{c: 3, d: 4}}
iex> ExUtils.Maps.stringify_keys(map, [:a, :b])
%{"a" => 1, "b" => %{c: 3, d: 4}}
iex> ExUtils.Maps.stringify_keys(map, [:a, :b], deep: true)
%{"a" => 1, "b" => %{c: 3, d: 4}}
iex> ExUtils.Maps.stringify_keys(map, [:a, :b, :d], deep: true)
%{"a" => 1, "b" => %{:c => 3, "d" => 4}}
iex> ExUtils.Maps.stringify_keys(map, [:a], drop: true)
%{"a" => 1}
iex> ExUtils.Maps.stringify_keys(map, :all, deep: true)
%{"a" => 1, "b" => %{"c" => 3, "d" => 4}}
```

# `symbolize_keys`

> This function is deprecated. Use ExUtils.Maps.atomize_keys/3 instead.

---

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