View Source Drops.Types.Map (drops v0.1.0)

Drops.Types.Map is a struct that represents a map type with optional constraints.

Examples

iex> Drops.Types.from_spec({:type, {:map, []}}, [])
%Drops.Types.Type{primitive: :map, constraints: [predicate: {:type?, :map}]}

iex> Drops.Types.from_spec(%{
...>   {:required, :name} => {:type, {:string, []}},
...>   {:optional, :age} => {:type, {:integer, []}}
...> }, [])
%Drops.Types.Map{
  primitive: :map,
  constraints: [predicate: {:type?, :map}],
  keys: [
    %Drops.Types.Map.Key{
      path: [:age],
      presence: :optional,
      type: %Drops.Types.Type{
        primitive: :integer,
        constraints: [predicate: {:type?, :integer}]
      }
    },
    %Drops.Types.Map.Key{
      path: [:name],
      presence: :required,
      type: %Drops.Types.Type{
        primitive: :string,
        constraints: [predicate: {:type?, :string}]
      }
    }
  ],
  atomize: false
}

Summary

Types

@type t() :: %Drops.Types.Map{
  atomize: term(),
  constraints: term(),
  keys: term(),
  primitive: term()
}

Functions

Link to this function

atomize(data, keys, initial \\ %{})

View Source