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
learn to use with correctly
2
siddhant3030
Thanks :).
1
Popular in Questions
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
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
Hi all,
Trying to get some more clarity over utc_datetime and naive_datetime for Ecto:
https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
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 t...
New
Hey,
I have a NanoPi-M3 and try to install Elixir on their Ubuntu image. I followed the Raspberry Pi installation instructions from the ...
New
I have a User schema with a :from_id field set to type :string:
defmodule TweetBot.Repo.Migrations.CreateUsers do
use Ecto.Migration
...
New
Hello, I have map which I want to convert it to string like this:
the map:
%{last_name: "tavakkoli", name: "shahryar"}
the string I ne...
New
After calling mix ecto.create I get this error:
17:00:32.162 [error] GenServer #PID<0.412.0> terminating
** (Postgrex.Error) FATAL...
New
In AR this is so simple
@articles = current_user.articles
How to do in Ecto?
def index(conn, _params) do
current_user = conn.assig...
New
Other popular topics
Here are few pieces of (common) Linux knowledge that we use for reasonably small one server apps. We use Ubuntu but this should work for ...
New
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set?
Thanks.
New
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
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
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
New
Hi guys, i’m new in the Elixir world, and i have to say, that i love it!
i’m having some problem to understand anonymous functions with ...
New
by Lance Halvorsen
Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
New
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New







