View Source Want.Integer (want v1.17.1)

Manages conversions to and from integers.

Summary

Functions

Cast a value to an integer.

Callback implementation for Want.Type.cast/2.

Types

@type result() :: {:ok, integer()} | {:error, binary()}

Functions

Cast a value to an integer.

Options

  • :max - Maximum allowable integer value.
  • :min - Minimum allowable integer value.

Examples

iex> Want.Integer.cast("1")
{:ok, 1}

iex> Want.Integer.cast(1.0)
{:ok, 1}

iex> Want.Integer.cast(:'1')
{:ok, 1}

iex> Want.Integer.cast({:a, :b})
{:error, "Failed to convert value {:a, :b} to integer."}

iex> Want.Integer.cast("10", max: 3)
{:error, "Integer value exceeds maximum 3."}

iex> Want.Integer.cast(1.0, min: 3)
{:error, "Integer value below minimum 3."}
@spec cast(value :: any(), opts :: Keyword.t()) :: result()

Callback implementation for Want.Type.cast/2.