How do you get module summary?

I’d like a quick overview for plus-sized modules, including name/arity of functions and what other functions each of them call. I thought there must be some obvious ways to do this. Is there?

Your best bets are probably:

iex> h ModuleName

or:

iex> ModuleName.<Press Tab>
3 Likes

I find module_info/0 and module_info/1 helpful sometimes. Erlang -- Modules .

__info__/1 also gives a summary of module.

iex(13)> i List
Term
  List
Data type
  Atom
Module bytecode
  /opt/homebrew/Cellar/elixir/1.14.1/bin/../lib/elixir/ebin/Elixir.List.beam
Source
  /private/tmp/elixir-20221011-1286-c062s/elixir-1.14.1/lib/elixir/lib/list.ex
Version
  [147103463495654681739219212155239184521]
Compile options
  [:no_spawn_compiler_process, :from_core, :no_core_prepare, :no_auto_import, :inline_list_funcs, {:inline, [last: 2]}, {:inline, [decrement: 1]}]
Description
  Use h(List) to access its documentation.
  Call List.module_info() to access metadata.
Raw representation
  :"Elixir.List"
Reference modules
  Module, Atom
Implemented protocols
  Ecto.Queryable, IEx.Info, Inspect, Jason.Encoder, List.Chars, Phoenix.HTML.FormData, Phoenix.HTML.Safe, Phoenix.Param, Plug.Exception, String.Chars, Swoosh.Email.Recipient, Timex.Protocol, Xema.Castable

Result of i List in IEx - Description has reference about module_info - Call List.module_info() to access metadata.

I find this very helpful when there is no help available for a module or sometimes just to see concise summary of module.

iex(14)> List.module_info()
[
  module: List,
  exports: [
    __info__: 1,
    ascii_printable?: 1,
    ascii_printable?: 2,
    delete_at: 2,
    duplicate: 2,
    first: 1,
    first: 2,
    flatten: 2,
    foldr: 3,
    improper?: 1,
    insert_at: 3,
    keydelete: 3,
    keyfind!: 3,
    keyreplace: 4,
    keysort: 2,
    keystore: 4,
    keytake: 3,
    last: 2,
    myers_difference: 2,
    myers_difference: 3,
    pop_at: 2,
    pop_at: 3,
    replace_at: 3,
    starts_with?: 2,
    to_atom: 1,
    to_existing_atom: 1,
    to_float: 1,
    to_integer: 1,
    to_integer: 2,
    to_tuple: 1,
    update_at: 3,
    zip: 1,
    module_info: 0,
    module_info: 1,
    keymember?: 3,
    keyfind: 4,
    flatten: 1,
    keyfind: 3,
    wrap: 1,
    foldl: 3,
    keysort: 3,
    delete: 2,
    to_charlist: 1,
    last: 1,
    to_string: 1
  ],
  attributes: [vsn: [147103463495654681739219212155239184521]],
  compile: [
    version: '8.2.1',
    options: [
      :no_spawn_compiler_process,
      :from_core,
      :no_core_prepare,
      :no_auto_import,
      :inline_list_funcs,
      {:inline, [last: 2]},
      {:inline, [decrement: 1]}
    ],
    source: '/private/tmp/elixir-20221011-1286-c062s/elixir-1.14.1/lib/elixir/lib/list.ex'
  ],
  md5: <<110, 171, 24, 181, 253, 63, 149, 218, 110, 99, 54, 250, 70, 198, 184,
    137>>
]
2 Likes