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

Specs

to_atom(integer() | float() | binary() | charlist()) :: atom() | no_return()

Attempt to convert the inbound value into an atom.

Link to this function

to_boolean(value)

Specs

to_boolean(any()) :: boolean() | no_return()

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.

Link to this function

to_float(value)

Specs

to_float(integer() | float() | binary() | charlist()) :: float() | no_return()

Attempts to convert the inbound value into an float.

Link to this function

to_integer(value)

Specs

to_integer(integer() | float() | binary() | charlist()) ::
  integer() | no_return()

Attempts to convert the inbound value into an integer.

Link to this function

to_string(value)

Specs

to_string(integer() | float() | binary() | charlist()) ::
  String.t() | no_return()

Attempt to convert the inbound value into an atom.