want v1.4.0 Want.Keyword
Manages conversions to and from keyword lists.
Link to this section Summary
Functions
Cast an incoming keyword list or map to an output keyword list using the provided schema to control conversion rules and validations.
Link to this section Types
Link to this section Functions
Cast an incoming keyword list or map to an output keyword list using the provided schema to control conversion rules and validations.
Examples
iex> Want.Keyword.cast(%{"id" => 1}, %{id: [type: :integer]})
iex> Want.Keyword.cast(%{}, %{id: [type: :integer, default: 1]})
iex> Want.Keyword.cast(%{"id" => "bananas"}, %{id: [type: :integer, default: 1]})
iex> Want.Keyword.cast(%{"hello" => "world", "foo" => "bar"}, %{hello: [], foo: [type: :atom]})
iex> Want.Keyword.cast(%{"hello" => "world"}, %{hello: [], foo: [required: true]})
iex> Want.Keyword.cast(%{"hello" => "world"}, %{hello: [], foo: []})
iex> Want.Keyword.cast(%{"hello" => "world"}, %{hello: [type: :enum, valid: [:world]]})
iex> Want.Keyword.cast(%{"hello" => %{"foo" => "bar"}}, %{hello: %{foo: [type: :atom]}})
iex> Want.Keyword.cast(%{"id" => "bananas"}, %{id: [type: :integer, default: 1]}, merge: [id: 2])