View Source Flamel.Wrap (flamel v1.10.0)

Some helper functions for wrapping and unwraping values in tuples

Summary

Functions

Takes a value and wraps it in a :cont tuple

Takes a value and wraps it in a :continue tuple

Takes a value and wraps it in a :error tuple

Takes a value and wraps it in a :noreply tuple

Takes a value and wraps it in a :ok tuple

Takes a value and wraps it in a :reply tuple

Takes a value and wraps it in a :stop tuple

Takes an {:ok, value} or {:error, message} tuple and returns the value

Takes a value and wraps it in a tuple with the specified atom as the first item

Functions

@spec cont(term()) :: {:cont, term()}

Takes a value and wraps it in a :cont tuple

Examples

iex> Flamel.Wrap.cont([])
{:cont, []}

iex> Flamel.Wrap.cont("message")
{:cont, "message"}
@spec continue(term()) :: {:continue, term()}

Takes a value and wraps it in a :continue tuple

Examples

iex> Flamel.Wrap.continue(:load_something)
{:continue, :load_something}

iex> Flamel.Wrap.continue("message")
{:continue, "message"}

iex> Flamel.Wrap.continue(:first, :second)
{:continue, :first, :second}
@spec continue(term(), term()) :: {:continue, term(), term()}
@spec error(term()) :: {:error, term()}

Takes a value and wraps it in a :error tuple

Examples

iex> Flamel.Wrap.error([])
{:error, []}

iex> Flamel.Wrap.error("message")
{:error, "message"}

iex> Flamel.Wrap.error(:first, :second)
{:error, :first, :second}
@spec error(term(), term()) :: {:error, term(), term()}

See Flamel.Result.error?/1.

@spec noreply(term()) :: {:noreply, term()}

Takes a value and wraps it in a :noreply tuple

Examples

iex> Flamel.Wrap.noreply([])
{:noreply, []}

iex> Flamel.Wrap.noreply("message")
{:noreply, "message"}

iex> Flamel.Wrap.noreply(:first, :second)
{:noreply, :first, :second}
@spec noreply(term(), term()) :: {:noreply, term(), term()}
@spec ok(term()) :: {:ok, term()}

Takes a value and wraps it in a :ok tuple

Examples

iex> Flamel.Wrap.ok([])
{:ok, []}

iex> Flamel.Wrap.ok("message")
{:ok, "message"}
@spec ok(term(), term()) :: {:ok, term(), term()}

See Flamel.Result.ok?/1.

@spec reply(term()) :: {:reply, term()}

Takes a value and wraps it in a :reply tuple

Examples

iex> Flamel.Wrap.reply([])
{:reply, []}

iex> Flamel.Wrap.reply("message")
{:reply, "message"}

iex> Flamel.Wrap.reply(:first, :second)
{:reply, :first, :second}
@spec reply(term(), term()) :: {:reply, term(), term()}
@spec stop(term(), term()) :: {:stop, term(), term()}

Takes a value and wraps it in a :stop tuple

Examples

iex> Flamel.Wrap.stop(:shutdown, %{})
{:stop, :shutdown, %{}}

Takes an {:ok, value} or {:error, message} tuple and returns the value

Examples

iex> Flamel.Wrap.unwrap({:ok, []})
[]

iex> Flamel.Wrap.unwrap({:error, "message"})
"message"

See Flamel.Result.error!/1.

Link to this function

unwrap_error_or_nil(value)

View Source

See Flamel.Result.error_or_nil/1.

See Flamel.Result.ok!/1.

See Flamel.Result.ok_or_nil/1.

@spec wrap(atom(), term()) :: {atom(), term()}

Takes a value and wraps it in a tuple with the specified atom as the first item

Examples

iex> Flamel.Wrap.wrap(:ok, [])
{:ok, []}

iex> Flamel.Wrap.wrap(:error, "message")
{:error, "message"}

iex> Flamel.Wrap.wrap(:stop, :shutdown, %{})
{:stop, :shutdown, %{}}
Link to this function

wrap(item, first, second)

View Source
@spec wrap(atom(), term(), term()) :: {atom(), term(), term()}