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

@spec 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)

@spec 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)

@spec 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)

@spec 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)

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

Attempt to convert the inbound value into an atom.