View Source WarmFuzzyThing behaviour (WarmFuzzyThing v0.1.0)
Provides a way of working with already known Elixir constructs through monads.
WarmFuzzyThing.Maybe represents the Union nil | {:ok, value} when value: any().
WarmFuzzyThing.Either represents the Union {:error, reason} | {:ok, value} when reason: any(), value: any().
To understand more about their general idea and implementation details, head over to their respective documentation.
Link to this section Summary
Functions
Converts a WarmFuzzyThing.Either to WarmFuzzyThing.Maybe
Functions that return the value itself.
Link to this section Types
@type t(a) :: WarmFuzzyThing.Either.t(any(), a) | WarmFuzzyThing.Maybe.t(a)
Link to this section Callbacks
Link to this section Functions
@spec either_to_maybe(WarmFuzzyThing.Either.t(reason, value)) :: WarmFuzzyThing.Maybe.t(value) when value: any(), reason: any()
Converts a WarmFuzzyThing.Either to WarmFuzzyThing.Maybe
example
Example
iex> WarmFuzzyThing.either_to_maybe({:ok, 1})
{:ok, 1}
iex> WarmFuzzyThing.either_to_maybe({:error, :not_found})
nil
@spec id(value) :: value when value: any()
Functions that return the value itself.
example
Example
iex> WarmFuzzyThing.id(10)
10
iex> WarmFuzzyThing.id({:ok, 10})
{:ok, 10}
iex> WarmFuzzyThing.id({:error, :not_found})
{:error, :not_found}
iex> WarmFuzzyThing.id(nil)
nil
@spec maybe_to_either(WarmFuzzyThing.Maybe.t(value), reason) :: WarmFuzzyThing.Either.t(reason, value) when value: any(), reason: any()
Converts a WarmFuzzyThing.Maybe to WarmFuzzyThing.Either
example
Example
iex> WarmFuzzyThing.maybe_to_either({:ok, 1}, :not_found)
{:ok, 1}
iex> WarmFuzzyThing.maybe_to_either(nil, :not_found)
{:error, :not_found}