hubertlepicki
So I want to check if a module exist and has some function defined. For example, I want to check if I have module Foo with foo/2 function defined. Any ideas?
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #security











Showing Posts 1 to 9- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
hubertlepicki
Looks like I can check for module existence this way:
dgamidov
@hubertlepicki may be it will help?
hubertlepicki
Yes! Thank you @dgamidov seems like I can do
that returns list of function names with arity. Perfect.
sashaafm
@hubertlepicki
Code.ensure_loaded/1doesn’t check if it exists. It checks if it is loaded and if not then it is loaded (or tries to load it):Qqwy
For posterity: It is more Elixir-like to use
Foo.__info__(:functions).:functionsis an alias of the Erlang-specific:exports, but a lot clearer. Also,__info__/1is the Elixir-wrapper around:erlang.module_info/1and allows slightly more atoms as input (such as:macros).See the docs for more information.
Also note that there are many functions inside the stdlib
Modulemodule , but most (except for__info__/1) only work during compile-time.rvirding
Do you want to test if the module is loaded and exports a specific function, or you do you want to test if there exists a module which you can reach at all containing the function? If it is the first then you have the function
:erlang.function_exported(module, function, arity). I don’t know if there is an Elixir interface function. The other alternative has already been covered here, but be aware that the solutions, when they check, will load the module if it not already loaded.hubertlepicki
yup, I am good with loading module if it hasn’t been loaded at all. I want to know if I can call this Module.function. If I load it doing that, it’s also ok.
Qqwy
Another thing that you might like to look at, are Behaviours. If your current use-case is to have later-defined modules (e.g. made by users of your library) that have to follow a fixed specification you provide, then Behaviours are the way to go.
kuroda
Elixir has the function Kernel.function_exported?/3, which returns
trueif the speficied module is loaded and contains a public function with the given arity, otherwisefalse.