Elixir Lab Examples
elixir demo/<group>/NN_name.exs, or open them in the code viewer and
change one thing, then run again — that second run is where the learning happens.
Foundations
Hello world, expressions, pipes, and scripts that read their environment — the four files every later demo assumes you have seen.
| # | Description | Link |
|---|---|---|
| 1 | Hello world — modules, interpolation, @doc and @moduledoc | View |
| 2 | Expressions and pipes — everything returns a value | View |
| 3 | Conditionals — if/unless, cond, and the case workhorse | View |
| 4 | Scripts that read the world — argv, env vars, and file IO | View |
Language Core
Immutability, matching, recursion, collections, polymorphism, errors, and binaries — the vocabulary of idiomatic Elixir.
| # | Description | Link |
|---|---|---|
| 5 | Immutability — rebinding, update syntax, structural sharing | View |
| 6 | Pattern matching — destructuring, pin, function heads | View |
| 7 | Guards and with — refining matches, happy-path pipelines | View |
| 8 | Functions and captures — defaults, closures, the & shorthand | View |
| 9 | Recursion and tail calls — body vs accumulator style | View |
| 10 | Enum and Stream — eager vs lazy pipelines on the same data | View |
| 11 | Comprehensions — for with generators, filters, and into: | View |
| 12 | Maps and structs — Access, update syntax, enforce_keys | View |
Protocols, Errors & Binaries
Polymorphism, failure idioms, and byte-level parsing — the three lessons that finish the language core.
| # | Description | Link |
|---|---|---|
| 13 | Protocols — defprotocol/defimpl and derived implementations | View |
| 14 | Behaviours — @callback contracts and @impl dispatch | View |
| 15 | Error handling — raise/rescue/after, tagged tuples, custom exceptions | View |
| 16 | Binaries and sigils — bitstring parsing of a wire frame | View |
Tooling
The AST, macros, tests, and property checks — the files that teach you how Elixir compiles and verifies itself.
| # | Description | Link |
|---|---|---|
| 17 | Quote and unquote — inspecting the AST of real expressions | View |
| 18 | Custom macros — a trace/1 macro with hygiene | View |
| 19 | ExUnit and doctests — a test suite that runs in one script | View |
| 20 | Property tests — StreamData roundtrip properties | View |
Concurrency & OTP
From raw spawn to supervised servers — the phase 4 pattern book in runnable form.
| # | Description | Link |
|---|---|---|
| 21 | Spawn, send, receive — a raw process with a mailbox | View |
| 22 | Links and monitors — crash propagation and :DOWN messages | View |
| 23 | Tasks — async/await and bounded async_stream pools | View |
| 24 | Agents — atomic get/update state holders | View |
| 25 | GenServer — a complete key/value server with call/cast/info | View |
Supervision & Shared State
Supervisors, dynamic children, registration, ETS, and telemetry — how systems stay up.
| # | Description | Link |
|---|---|---|
| 26 | Supervisor — one_for_one tree with crash-loop protection | View |
| 27 | DynamicSupervisor — sessions started and stopped at runtime | View |
| 28 | Registry — named processes for per-user state | View |
| 29 | ETS — shared read/write tables and concurrent access | View |
| 30 | Telemetry — instrumenting a module with event handlers | View |
Ecosystem
Ecto, Broadway, Nx, and Plug — single-file scripts made runnable with Mix.install/2 (network access needed on first run).
| # | Description | Link |
|---|---|---|
| 31 | Ecto changesets — schema + validation pipeline, no database required | View |
| 32 | Broadway pipeline — a custom producer with back-pressure | View |
| 33 | Nx tensors — defn functions and a softmax | View |
| 34 | Plug pipeline — a minimal HTTP app on Bandit | View |
| 35 | Oban worker — a job definition (study demo: needs PostgreSQL) | View |
| 36 | Release config — application env read from runtime.exs (study demo) | View |
elixir demo/core/06_pattern_matching.exs. Ecosystem demos (31–34) start with
Mix.install/2 and fetch their dependencies from Hex on first run. Demos 35–36 need a
PostgreSQL service (35) or a release build (36) and are written to be read and studied in the
viewer. Larger multi-file study projects are on the Study Projects page.