Free course · 10 lessons · Beginner

Elixir Fundamentals: Functional Programming and OTP

Learn Elixir from the ground up: immutable data, pattern matching, multi-clause functions and pipes, collections and Enum, control flow with with, error handling and "let it crash", then processes, message passing, Tasks, GenServers and Supervisors, testing with ExUnit, and where Phoenix and LiveView fit. Every example runs on the BEAM and is shown with its real output.

Start the course

1. Functional Elixir: Data, Pattern Matching and Functions

Immutable data, pattern matching, functions with multiple clauses and guards, the pipe operator, collections, Enum and recursion: the functional core of Elixir.

  1. Hello, Elixir: Basic Types and Immutability — Run Elixir scripts and IEx, meet the basic types (integers, floats, atoms, strings, booleans, nil), string interpolation, and the rule that data never changes: you transform it into new data.
  2. Pattern Matching: The = Operator Is a Match — In Elixir, = matches a pattern against data and binds variables. Destructure tuples, lists and maps, use the pin operator ^ to match an existing value, and handle {:ok, value} and {:error, reason} results.
  3. Functions, Modules, Guards and the Pipe Operator — Group functions in modules, write several clauses of one function that pattern-match their arguments, add guards, use default arguments and anonymous functions, and chain transformations with |>.
  4. Lists, Maps, Structs, Enum and Recursion — Work with lists, keyword lists, maps and structs; transform them with Enum (map, filter, reduce, group_by, sort_by) and comprehensions; and understand recursion, the functional replacement for loops.
  5. Control Flow: case, cond, if and with — Choose between case (match a value against patterns), cond (first true condition), if/unless (one boolean), and with (a happy-path pipeline of steps that each must succeed).

2. Processes, OTP and Fault Tolerance

What makes Elixir special: lightweight processes that share nothing, message passing, Tasks, GenServers for state, Supervisors that restart failures, and the 'let it crash' philosophy. Then a capstone.

  1. Errors, Tagged Tuples and 'Let It Crash' — Use {:ok, value} / {:error, reason} for expected failures, raise and rescue for exceptional ones, define custom exceptions, and understand why Elixir code often lets processes crash and restarts them instead of defending against every error.
  2. Processes and Message Passing — Spawn lightweight processes, send and receive messages, use Task for concurrent work, and see why the BEAM can run hundreds of thousands of isolated processes with no shared memory.
  3. GenServer and Supervisors: OTP in Practice — Keep state in a GenServer with call (synchronous) and cast (asynchronous) messages, start it under a Supervisor, and watch the supervisor restart it after a crash. This is the backbone of every Elixir and Phoenix app.
  4. Mix, Testing and the Phoenix Ecosystem — Create projects with Mix, manage dependencies from Hex, write tests with ExUnit and doctests, and see where Phoenix, LiveView, Ecto and Oban fit when you build real web apps.
  5. Capstone: A Chat Room Server — Design a supervised chat room service: one process per room, a registry to find rooms by name, message history with a size limit, and clean handling of crashes. Build it, then review it against the rubric.

Was this page helpful?