View Source Want.Enum (want v1.17.1)

Provides type conversions to enumerations.

Summary

Functions

Cast a given value to an enum value. The given options keyword list must include an array of valid enum values under the :valid key, otherwise the function will return an error tuple.

Types

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

Functions

@spec cast(value :: any(), opts :: Keyword.t()) :: result()

Cast a given value to an enum value. The given options keyword list must include an array of valid enum values under the :valid key, otherwise the function will return an error tuple.

Options

  • :valid - List of valid enum values. The input must loosely match one of these.

Examples

iex> Want.Enum.cast("hello", valid: [:hello, :world])
{:ok, :hello}

iex> Want.Enum.cast("hello", valid: ["hello", :world])
{:ok, "hello"}
Link to this function

cast(value, opts, valid)

View Source