Lamina.Cast (lamina v0.4.2)
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.
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.
Functions
to_atom(value)
Attempt to convert the inbound value into an atom.
to_boolean(value)
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)
Attempts to convert the inbound value into an float.
to_integer(value)
Attempts to convert the inbound value into an integer.
to_string(value)
Attempt to convert the inbound value into an atom.