happy_with v1.0.0 HappyWith

Summary

Macros

Rewrites the given block and else clauses into Elixir’s standard with form

Macros

happy_with(list)

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"