When I use “cond” | Elixir / Phoenix

Photo by Miti on Unsplash

I’ve told that I like the “with” statement in my first post because the “with” statement can check all conditions which are requirements to do what we want to at once. For instance, the API which needs 3 request parameters, so we have to validate them if each of them is nil or not.

“with” can check all request params before executing the function.

However, what if I have to response a specific error code with the specific message for each lack of request parameters?

I will use the “cond” statement for this.

Check each request parameters by cond to response an error code one by one.

But what if there were 100 request parameters for an API? Will you write 100 conditions? And besides, we can say that this way can response just one error response.

So I will tell you another way in the next post, even though we have to check all each parameter.

--

--