Elixir
December 18, 2021
In Elixir, is there a way to determine if a module exists?
You can use Code.ensure_compiled?/1
, but there is a side effect: it will also attempt to load the module if it is not already, which may not be desired (depending on the use-case).
Here is an approach that should work without any side effects:
iex> function_exported?(String, :__info__, 1) true iex> function_exported?(NoModule, :__info__, 1) false
Elixir modules export :__info__/1
so testing for it provides a generic solution.