I have 2 modules, one of them has a function that returns a list and the other one is using that function to create a module attribute.
Is this a safe operation in Elixir? I’m not sure if it’s guaranteed that the first module will be compiled before the second one. Also, does it matter if the modules are in the same file/different files?
e.g:
defmodule Producer do
def special_list do
[1,2,3]
end
end
defmodule Consumer do
@special_attribute Producer.special_list()
end
The compiler will detect that you are calling a remote function on the Producer module and will compile the Producer module if it needs to. So yes, it’s a safe thing to do and quite a common pattern.