So I have this problem where I am doing multiple function calls inside a function, and with each function call, I check to see if the result that I am getting is true
or not.
For example:
defmodule Example do
def helper(arr, index_start, index_end) do
cond do
index_start > index_end -> false
arr[index_start] > arr[index_end] -> false
true ->
{right, top} = {index_start + 1, index_end + 1}
res = helper(arr, index_start+right, index_end+top)
case res do
true -> true
_ ->
{left, down} = {index_start - 1, index_end - 1}
res = helper(arr, index_start-left, index_end-down)
case res do
true -> true
_ ->
{upleft, rightdown} = {index_start + index_end, index_end - index_start}
res = helper(arr, upleft, rightdown)
case res do
true -> true
_ -> false
end
end
end
end
end
end
Btw, this is simply an example code that I just wrote that makes no sense so it might have an issue if you try running it. Just wanted to show what I wanted to do.
Now, over here, I am calling the helper
function multiple times and checking its result. What’s the best approach to do something like this in Elixir?
Calling multiple case
or cond
inside a function makes it very messy. Would appreciate it if someone could explain this using an example.