Module and Function Basics

Elixir is a functional language, so—as you would expect—the work of an Elixir application is done in functions. Functions take input data, process it according to the function’s code, and then return a result. Modules are containers of functions that you have grouped together. They are mainly used as an organizational tool.

We are talking about modules and functions at the same time because they go hand-in-hand with each other. A module doesn’t serve a purpose without functions, and functions need a module to exist in.

The main purpose of modules is to hold functions, but they actually do more than this. Later in this chapter, we’ll look at additional syntax that’s available to modules.

We’ll cover two types of functions ...

Get From Ruby to Elixir now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.