helf v0.0.1 HELF.Flow

Link to this section Summary

Functions

Stores a callback to be executed at the end of the with, no matter if it succeeds or fails

Stores a callback to be executed if the with fails

Stores a callback to be executed if the with succeeds

Link to this section Functions

Link to this macro flowing(list) (macro)
Link to this function on_done(callback)
on_done((() -> any)) :: :ok

Stores a callback to be executed at the end of the with, no matter if it succeeds or fails

Eg:

flowing do
  with     on_done(fn -> IO.puts "The flow is completed" end),
    {:ok, value} <- Map.fetch(%{a: 1}, :a)
  do
    flowing do
      with         on_done(fn -> IO.puts "The other flow is completed" end),
        {:ok, value} <- Map.fetch(%{a: 1}, :b)
      do
        :gotcha
      end
    end
  end
end
Link to this function on_fail(callback)
on_fail((() -> any)) :: :ok

Stores a callback to be executed if the with fails

Eg:

flowing do
  with     on_fail(fn -> IO.puts "Operation failed" end),
    {:ok, value} <- Map.fetch(%{a: 1}, :b),
    on_success(fn -> IO.puts "Succeeded and got #{inspect value}" end)
  do
    :gotcha
  end
end
Link to this function on_success(callback)
on_success((() -> any)) :: :ok

Stores a callback to be executed if the with succeeds

Eg:

flowing do
  with     on_fail(fn -> IO.puts "Operation failed" end),
    {:ok, value} <- Map.fetch(%{a: 1}, :a),
    on_success(fn -> IO.puts "Succeeded and got #{inspect value}" end)
  do
    :gotcha
  end
end