Get a list of all elixir modules in IEx

一世执手 提交于 2019-12-24 00:43:57

问题


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?


回答1:


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




回答2:


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", ... ]


来源:https://stackoverflow.com/questions/58461572/get-a-list-of-all-elixir-modules-in-iex

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!