Lamina.Cast (lamina v0.4.0)
A helpful library of casts.
Defining a cast function is brain-dead simple, however sometimes you just don't want to write the same thing over and over. Here is a helpful pile of functions for common configuration castings.
Feel free to open a PR to add more.
Link to this section Summary
Functions
Attempt to convert the inbound value into an atom.
Attempt to convert the inbound value into a boolean.
Attempts to convert the inbound value into an float.
Attempts to convert the inbound value into an integer.
Attempt to convert the inbound value into an atom.
Link to this section Functions
to_atom(value)
Specs
Attempt to convert the inbound value into an atom.
to_boolean(value)
Specs
Attempt to convert the inbound value into a boolean.
Things that are considered true:
- A literal
true
. - The words "true" or "yes" in any capitalisation.
Everything else is false.
to_float(value)
Specs
Attempts to convert the inbound value into an float.
to_integer(value)
Specs
Attempts to convert the inbound value into an integer.
to_string(value)
Specs
Attempt to convert the inbound value into an atom.