O'Reilly logo

Elixir Cookbook by Paulo A Pereira

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 4. Modules and Functions

This chapter will cover the following recipes:

  • Namespacing modules
  • Using module attributes as constants
  • Enforcing behaviors
  • Documenting modules
  • Using module directives
  • Using a module in the scripted mode
  • Defining functions with default arguments
  • Using guard clauses and pattern matching in function definitions

Introduction

Elixir modules are files (see the following information box) where related functions are grouped and stored. In Chapter 1, Command Line, we covered how to load and compile our own modules in IEx and how to generate applications with Mix. Mix applications are a collection of modules within a predefined directory structure.

Modules are defined using the defmodule macro and functions using the def and defp ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required