Magik.Maybe.run
You're seeing just the function
run
, go back to Magik.Maybe module for more information.
This function is mostly used with with
. In some case, you may want to invoke a function if it meets a specific condition without breaking with
into 2 block like this
params = %{} with {:ok, data} <- insert_something(),
:ok <- (if params.checked, do: do_something(data), else: :ok),
{:ok, another_data} <- send_something(data) do
# aha
end
This function help to write it shorter
params = %{} with {:ok, data} <- insert_something(),
:ok <- Maybe.run(params.checked, &do_something(data)),
{:ok, another_data} <- send_something(data) do
# aha
end