I am currently struggle with this requirement. For example, I have a list of functions.
def function_a(a, b, c, d) do
...
function_b(a, b)
...
end
defp function_b(a, b) do
...
function_c(a, b)
...
end
defp function_c(a, b) do
...
function_d(a, b)
...
end
defp function_d(a, b) do
IO.inspect a
IO.inspect b
end
Now I want to add IO.inspect d in the function_d. The only way I can think of, is to pass the d as parameter for each function. Which means I need modify function_b, function_c, function_d(In real world, it's more).
In OOP world, we can store the d as an instance variable, and any function in this class can use it directly.
The reason I am asking this question, is that I want to avoid to increase the number of parameters.
Is there any good way in Elixir or Phoenix?
def function_a(my_struct) dowould callfunction_b(my_struct)anddefp function_d(my_struct) dowould just callIO.inspect(my_struct.d). Please not that structs are not the same as OOP classes, but they might help define the shape of the data in a similar way. - sabiwaraoptionsordata. But here I don't want to use this way because it breaks some meaning of the code. - Stephen