ExToolkit.Map (ExToolkit v0.12.6)

View Source

This module provides utilities for working with maps.

Summary

Functions

Recursively converts a struct into a plain map, transforming all nested structs, maps, and lists along the way.

Functions

deep_from_struct(data)

@spec deep_from_struct(struct()) :: map()

Recursively converts a struct into a plain map, transforming all nested structs, maps, and lists along the way.

Only accepts a struct at the top level. If a non-struct is passed, it will raise a FunctionClauseError.

If you don't want to do a deep recursive conversion you should use Map.from_struct/1.

Examples

iex> outer = %URI{host: "test", scheme: %{info: %URI{host: 42, authority: nil, fragment: nil, path: nil, port: nil, query: nil, scheme: nil, userinfo: nil}}}
iex> ExToolkit.Map.deep_from_struct(outer)
%{
  host: "test",
  scheme: %{info: %{host: 42, authority: nil, fragment: nil, path: nil, port: nil, query: nil, scheme: nil, userinfo: nil}},
  authority: nil,
  fragment: nil,
  path: nil,
  port: nil,
  query: nil,
  userinfo: nil
}