View Source Moar.Sugar (Moar v1.62.0)
Syntactic sugar functions.
These functions are intended to be used by importing the functions or the whole module:
import Moar.Sugar, only: [noreply: 1]
def handle_event("foo", _params, socket) do
socket |> assign(foo: "bar") |> noreply()
end
Summary
Functions
Wraps a term in an :error tuple. Useful in pipelines.
Unwraps an :error tuple, raising if the term is not an :error tuple.
Wraps a term in a :noreply tuple. Useful in pipelines.
Wraps a term in an :ok tuple. Useful in pipelines.
Unwraps an :ok tuple, raising if the term is not an :ok tuple.
Accepts two arguments and returns the second.
Functions
Wraps a term in an :error tuple. Useful in pipelines.
iex> %{} |> Map.put(:count, "unknown") |> Moar.Sugar.error()
{:error, %{count: "unknown"}}
Unwraps an :error tuple, raising if the term is not an :error tuple.
iex> {:error, 1} |> Moar.Sugar.error!()
1
Wraps a term in a :noreply tuple. Useful in pipelines.
iex> %{} |> Map.put(:count, 0) |> Moar.Sugar.noreply()
{:noreply, %{count: 0}}
Wraps a term in an :ok tuple. Useful in pipelines.
iex> %{} |> Map.put(:count, 10) |> Moar.Sugar.ok()
{:ok, %{count: 10}}
Unwraps an :ok tuple, raising if the term is not an :ok tuple.
iex> {:ok, 1} |> Moar.Sugar.ok!()
1
Accepts two arguments and returns the second.
Useful at the end of the pipeline when you want to return a different value than the last result of the pipeline, such as when the pipeline has side effects.
iex> %{} |> Map.put(:count, 20) |> Moar.Sugar.returning(:count_updated)
:count_updated