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
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
lets say i have a sample like
a = 20; b = 10;
if (a > b) do
{:ok, "a"}
end
if (a < b) do
{:ok, b}
end
if (a == b) do
{:ok, "equa...
New
If I have a post route which an argument:
post /my_post_route/:my_param1, MyController.my_post_handler
How would get the post params ...
New
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
What is the idiomatic way of matching for not nil in Elixir?
E.g.,
First way:
defp halt_if_not_signed_in(conn, signed_in_account) when...
New
i’m a new one to elixir
which editor can i use
vs code? or atom?
Thanks! :smiley:
New
Other popular topics
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
Hi there,
I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set?
Thanks.
New
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
If I have a post route which an argument:
post /my_post_route/:my_param1, MyController.my_post_handler
How would get the post params ...
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
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









