Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Elixir Cookbook
  • Table Of Contents Toc
  • Feedback & Rating feedback
Elixir Cookbook

Elixir Cookbook

By : Paulo Pereira
4.5 (2)
close
close
Elixir Cookbook

Elixir Cookbook

4.5 (2)
By: Paulo Pereira

Overview of this book

This book is intended for users with some knowledge of the Elixir language syntax and basic data types/structures. Although this is a cookbook and no sequential reading is required, the book’s structure will allow less advanced users who follow it to be gradually exposed to some of Elixir’s features and concepts specific to functional programming. To get the most out of this book, you need to be well versed with Erlang.
Table of Contents (11 chapters)
close
close
10
Index

Getting help and accessing documentation within IEx

Documentation is a first-class citizen in the Elixir ecosystem, so it comes as no surprise that IEx provides convenient ways to access documentation and get help without the need to leave an IEx session.

This recipe exemplifies the use of the defined help functions.

How to do it…

We will follow these steps to get help and access documentation in an IEx session:

  1. Enter h inside a running IEx session to see the help options related to the use of IEx helpers, as shown in this screenshot:
    How to do it…
  2. If we wish, for instance, to get information regarding the c/2 function, we type h(c/2), as shown in the following screenshot:
    How to do it…
  3. Accessing a module documentation is done by invoking h(ModuleName). In the next screenshot, we access documentation related to Enum:
    How to do it…
  4. Getting information about a specific function inside a module is also possible by invoking h(ModuleName.function_name). The following screenshot shows the documentation for Enum.map:
    How to do it…

How it works…

When we define modules, it is possible to use the @moduledoc and @doc annotations to define documentation related to the whole module or to a specific function in that module.

IEx parses the documentation defined with these annotations and makes it available in a convenient way so that there's no need to leave the session when help or some more information is needed.

IEx itself has several helper functions defined (refer to the first screenshot of this recipe), and among them, we find h/0 and h/1.

Note

It is common to refer to functions by their name followed by / and a number indicating the number of arguments that function takes. Therefore, h/0 is a function named h that takes 0 arguments, and h/1 is the same h function but with 1 argument.

There's more…

There are several defined functions that allow accessing information on function specifications and types (if defined). To learn more, you can use s/1 and t/1.

As an example, to get information on the types defined for the Enum module, we would use t(Enum), and to get information on the specifications, we would use s(Enum).

Visually different images
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Elixir Cookbook
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon