Dogma v0.1.16 Dogma.Rule.FinalCondition
A rule that checks that the last condition of a cond
statement is true
.
For example, prefer this:
cond do
1 + 2 == 5 ->
"Nope"
1 + 3 == 5 ->
"Uh, uh"
true ->
"OK"
end
Not this:
cond do
1 + 2 == 5 ->
"Nope"
1 + 3 == 5 ->
"Nada"
_ ->
"OK"
end
This rule will only catch those cond
statements where the last condition
is a literal or a _
. Complex expressions and function calls will not
generate an error.
For example, neither of the following will generate an error:
cond do
some_predicate? -> "Nope"
var == :atom -> "Yep"
end
cond do
var == :atom -> "Nope"
some_predicate? -> "Yep"
end
An atom may also be used as a catch-all expression in a cond
, since it
evaluates to a truthy value. Suggested atoms are :else
or :otherwise
.
To allow one of these instead of true
, pass it to the rule as a
:catch_all
option.
If you would like to enforce the use of _
as your catch-all condition, pass
the atom :_
into the :catch_all
option.
cond do
_ -> "Yep"
end
cond do
:_ -> "Yep"
end
Summary
Functions
Callback implementation for c:Dogma.Rule.test/2