View Source Want.Integer (want v2.0.0)
Manages conversions to and from integers.
Summary
Types
Functions
Cast a value to an integer.
Options
:max- Maximum allowable integer value.:min- Minimum allowable integer value.:clamp- If true, values outside:min/:maxare clamped to the boundary instead of failing.
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."}
iex> Want.Integer.cast(150, max: 100, clamp: true)
{:ok, 100}
iex> Want.Integer.cast(-5, min: 0, clamp: true)
{:ok, 0}
Callback implementation for Want.Type.cast/2.