Rijidaru
How to return or break from an action early?
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.
Marked As Solved
chulkilee
If you’re conditions are more of flat, then case with multiple match inside func or pattern match on func would be enough.
If your case is more complicated - such as 5 sequential validation and return in the middle of it - then use with or running multiple func as pipeline. Something like Plug. See this talk
Also Liked
NobbZ
No. There is only a draft about data points which have to exist mutually exclusive.
I can not find any code example that shows actual code or how incomming data is actually structured.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








