want v1.1.1 Want.Enum

Provides type conversions to enumerations.

Link to this section 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.

Link to this section Types

Link to this type

result()

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

Link to this section Functions

Link to this function

cast(value, opts)

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])

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

Link to this function

cast(value, opts, valid)