siddhant3030
Function body is nested too deep
I have a case statement that is failing in credo. Giving me this error
“Function body is nested too deep” I know we can use “with” here but I’m failing to use it correctly
case NaiveDateTime.from_iso8601(valid_time) do
{:ok, datetime} ->
case Somefunction(which give me true or false) do
true -> true
false -> false
end
{:error, _} ->
"datetime is not valid"
end
Guide me
Marked As Solved
lucaong
As you are mapping the return value of the function to itself, you can just avoid the inner case:
case NaiveDateTime.from_iso8601(valid_time) do
{:ok, datetime} ->
Somefunction(which give me true or false)
{:error, _} ->
"datetime is not valid"
end
In this case, I don’t think that with would help (but it might, depending on the code outside the outer case statement, which we don’t see).
5
Also Liked
mudasobwa
Creator of Cure
In this particular case, @lucaong already provided the best suggestion. In general, we usually introduce a private function with several clauses in such a case.
valid_time
|> NaiveDateTime.from_iso8601()
|> do_validate_instead_of_case()
[...]
defp do_validate_instead_of_case({:ok, datetime}) do
case Somefunction(which give me true or false) do
...
end
end
defp do_validate_instead_of_case({:error, _}),
do: "datetime is not valid"
3
Sebb
siddhant3030
Last Post!
siddhant3030
Popular in Questions
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
I have an umbrella app.
Some of the apps inside depend on other apps in the umbrella, unsurprisingly.
I’m writing a test for one of the...
New
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
Hi All,
I set a environment variables in dev.exs , like below code.
when i start server, how can i set the ${enable} value?
thanks.
d...
New
Good day to you all.
I have been struggling to get a query involving like and ilike to work.
Can anyone assist me on this, please?
pro...
New
Hi,
I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
Other popular topics
Hi,
I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
Hello!
Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
Hello all!
I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
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
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









