View Source Want.Boolean (want v1.18.0)

Performs type conversions to boolean values.

Summary

Functions

Cast a value to a boolean.

Callback implementation for Want.Type.cast/2.

Types

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

Functions

@spec cast(value :: any()) :: result()

Cast a value to a boolean.

Examples

iex> Want.Boolean.cast("true")
{:ok, true}

iex> Want.Boolean.cast("false")
{:ok, false}

iex> Want.Boolean.cast("TRUE")
{:ok, true}

iex> Want.Boolean.cast(1.0)
{:ok, true}

iex> Want.Boolean.cast(0)
{:ok, false}

iex> Want.Boolean.cast({:a, :b})
{:error, "Failed to convert value {:a, :b} to boolean."}
@spec cast(value :: any(), opts :: Keyword.t()) :: result()

Callback implementation for Want.Type.cast/2.