In an action I need to check numerous times if certain params have been passed. Some params are optional, others depend on others. That is, if one param is nil, its counterpart must be present.
How can I return or break early from an action once I encounter that a mandatory parameter hasn’t been passed?
I know, that I could restructure my code in such as a way, that a whole “if … then … else” tree will return “render” in the end. But it’d be a very complex, deeply nested “if … then … else” tree. I want to break early instead.
I am not especially familiar with the concept of “action”, but from an Erlang point of view i would agree with @chulkilee : if you declare functions with all the combinations that you expect to encounter and that are valid,
you would only need to keep the specific instructions for each case inside that function and leave the rest for a common function called further.
I have read somewhere (I think) that there is an added value in using functions with mathing signatures because they could bring benefits that the case statement could not, but I can’t remember I’d have to look it up. Basically I think that something like :
Res = process(MostProbableArgs),
Return = [ X bor Y || X <- Res, Y <- Args ];
logger:log(notice, "you are doing strage operations !"),
Return = weird.
If this is enough for you to solve your issue I think it might be a pretty easy way to do it, but I do not know about the specifics related to Elixir unfortunately so I can’t really help about that