View Source Want.List (want v1.22.0)
Manages conversions to and from lists.
Summary
Functions
Cast an input into a list. By default this function will simply break up the input into list elements, but
further casting and validation of elements can be performed by providing an element option. The separator
used to split the list defaults to the comma character and this can be controlled using the separator option.
Callback implementation for Want.Type.cast/2.
Types
@type element() :: any()
Functions
Cast an input into a list. By default this function will simply break up the input into list elements, but
further casting and validation of elements can be performed by providing an element option. The separator
used to split the list defaults to the comma character and this can be controlled using the separator option.
Options
:separator- Determines the character(s) used to separate list items. Defaults to the comma character.:element- Provides the ability to further control how list elements are cast and validated. Similar to themapandkeywordsfunctions, accepts a keyword list with its own:typefield and validation options.
Examples
iex> Want.List.cast("1")
{:ok, ["1"]}
iex> Want.List.cast("1", element: [type: :integer])
{:ok, [1]}
iex> Want.List.cast("1,2,3,4", element: [type: :integer])
{:ok, [1, 2, 3, 4]}
iex> Want.List.cast("1:2:3:4", separator: ":", element: [type: :integer])
{:ok, [1, 2, 3, 4]}
iex> Want.List.cast("hello:world", separator: ":", element: [type: :enum, valid: [:hello, :world]])
{:ok, [:hello, :world]}
iex> Want.List.cast("hello:world", separator: ":", element: [type: :enum, valid: [:hello]])
{:ok, [:hello]}
Callback implementation for Want.Type.cast/2.