AssignWhen
Allows the use of when clauses on assignment statements as an alternative to using if,
avoiding the need for boilerplate else clauses which return the original variables when
the condition is false.
Statements like this:
x = if condition(), do: whatever, else: xcan be replaced with code like this:
x = whatever when condition()For instance you can write
x = 1 when x == nilExports no functions, just a macro. The macro does no validation, but it does work on tuples and anything else that can be expressed as THING = THING
Macro code originally by José Valim
Installation
The package can be installed by adding assign_when to your list of dependencies
in mix.exs:
def deps do
[
{:assign_when, "~> 0.1.0"}
]
endThe documentation for this package can be found at https://hexdocs.pm/assign_when.