Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get a list of all elixir modules in IEx

To get a list of all functions on a module in IEx I can run:


Map.__info__(:functions)
# or
Enum.__info__(:functions)


Using the {Module}.__info__(:functions) format.

How can I get a list of all the standard lib modules?

like image 996
Loading... Avatar asked Jan 25 '23 17:01

Loading...


2 Answers

If you want to get all loaded Elixir modules, without erlang modules, run the following in a clean IEx shell:

:code.all_loaded() 
|> Enum.filter(fn {mod, _} -> "#{mod}" =~ ~r{^[A-Z]} end)
|> Enum.map(fn {mod, _} -> mod end)

# [Exception, Application, Inspect.Atom, IEx.Pry, Logger.Config, Module, Keyword, ... ]

This will also include sub modules like IEx.Config, but you can filter them with some additional mapping:

:code.all_loaded() 
|> Enum.filter(fn {mod, _} -> "#{mod}" =~ ~r{^[A-Z]} end)
|> Enum.map(fn {mod, _} -> mod end)
|> Enum.map(fn mod -> hd(Module.split(mod)) end)
|> Enum.uniq

# ["Exception", "Application", "Inspect", "IEx", "Logger", "Module", "Keyword", ... ]
like image 159
Jonas Dellinger Avatar answered Jan 28 '23 05:01

Jonas Dellinger


From IEx you can type : + Tab to get a list of all available modules.

like image 22
Adam Millerchip Avatar answered Jan 28 '23 06:01

Adam Millerchip