I have that kind piece of code:
case sth of
{a, 1} -> doA();
{a, 2} -> doA();
{a, 3} -> doB()
end.
Is there a way not to repeat "doA()" part? I thought that it should be easy, but I couldn't found answer in google.
You can use when guards in the case statement such as:
case sth of
{a, Var} when Var < 3-> doA();
{a, 3} -> doB()
end.
Also your expression(sth
) is an atom here meaning it can never match any of those cases.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With