constructor v1.1.0 Constructor.Convert
Functions in this module will typically perform a type conversion and then a validation.
Link to this section Summary
Functions
Converts nil to []
Converts a binary to an atom. The same warnings in String.to_atom/1 apply here
Converts v to a boolean, in an opinionated manner
Same as to_boolean/1, except nil will NOT be converted to false
Converts an atom such as :foo to "FOO"
Converts a binary to an existing atom. The same warnings in String.to_atom/1 apply here
Converts v to a float, returning a validation error if it cannot
Same as to_float/1, except that nil will NOT be converted to a float
Convert nil and "" to 0, and attempt to convert floats and binaries to integers
Same as to_integer/1, except nil will NOT be converted to an integer
Converts integers, floats and atoms to an equivalent string representation. nil is converted to
""
Same as to_string/1, except that nil will NOT be converted to a string.
""
Link to this section Types
error()
error() :: {:error, String.t()}
error() :: {:error, String.t()}
Link to this section Functions
nil_to_list(v)
Converts nil to [].
to_atom(item)
Converts a binary to an atom. The same warnings in String.to_atom/1 apply here.
to_boolean(v)
Converts v to a boolean, in an opinionated manner.
In order to be useful, this function makes some assumptions about what is truth-y or false-y.
"true"and"false"are converted totrueandfalserespectively. All strings are downcased first.- integers and floats greater than 0 are
true - integers and floats less than or equal to 0 are
false niland""arefalse
to_boolean_or_nil(v)
Same as to_boolean/1, except nil will NOT be converted to false
to_enum_string(e)
Converts an atom such as :foo to "FOO".
to_existing_atom(item)
Converts a binary to an existing atom. The same warnings in String.to_atom/1 apply here.
to_float(v)
Converts v to a float, returning a validation error if it cannot.
to_float_or_nil(v)
Same as to_float/1, except that nil will NOT be converted to a float.
to_integer(v)
Convert nil and "" to 0, and attempt to convert floats and binaries to integers.
to_integer_or_nil(v)
Same as to_integer/1, except nil will NOT be converted to an integer.
to_string(v)
Converts integers, floats and atoms to an equivalent string representation. nil is converted to
""
to_string_or_nil(v)
Same as to_string/1, except that nil will NOT be converted to a string.
""