happy_with v1.0.1 HappyWith
Link to this section Summary
Functions
Rewrites the given block and else clauses into Elixir’s standard with
form
Link to this section Functions
Rewrites the given block and else clauses into Elixir’s standard with
form.
iex> import HappyWith
iex> happy_with do
...> {:ok, name} <- {:ok, "joSE"}
...> lower = String.downcase(name)
...> lower
...> end
"jose"
You can also provide else clauses to the with
form.
iex> import HappyWith
iex> happy_with do
...> {:ok, name} <- {:error, :nobody}
...> _never_reached = String.downcase(name)
...> else
...> {:error, _} -> "luis"
...> end
"luis"
You can also use tags a feature from the happy project.
iex> import HappyWith
iex> happy_with do
...> @something {:ok, name} when is_binary(name) and length(name) > 3 <- {:error, :nobody}
...> _never_reached = String.downcase(name)
...> else
...> {:something, {:error, _}} -> "could not fetch name"
...> end
"could not fetch name"