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

Link to this section Types

Link to this section Callbacks

@callback bind(t(a), (a -> t(b))) :: t(b) when a: any(), b: any()
@callback fmap(t(a), (a -> b)) :: t(b) when a: any(), b: any()
Link to this callback

fold(t, default, function)

View Source
@callback fold(t(a), default :: b, (a -> b)) :: b when a: any(), b: any()
@callback pure(a) :: t(a) when a: any()
@callback sequence([t(a)]) :: t([a]) when a: any()

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
Link to this function

maybe_to_either(maybe, reason)

View Source
@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}