General Question
Can a single elixir file contain multiple modules? and can one import functions from different modules?
General Question
Can a single elixir file contain multiple modules? and can one import functions from different modules?
Yes, both is possible.
Coool…and how do i import a function from a different module stored in a different .ex file?
As I’m now on a proper computer, and do not have to type on a mobile, I want to say, that I usually do not like to import
. They usually pollute my own namespace with functions I might not even use.
Also when you find an unqualified call, you usually do look in the current module first and will probably not find it, but then you have to wade through a possibly long list of import
s to wade through, to find the module from which the function is imported.
You should prefer a fully qualified remote call (e.g. MyApp.Repo.get(…)
) or using aliases (e.g. alias MyApp.Repo; Repo.get
or alias MyApp.Repo, as: R; R.get(…)
)