Elixir Lab Examples

Thirty-six runnable single-file Elixir scripts that follow the track's lesson order, grouped by phase. Every file is self-contained and fully commented. Run them with 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.

#DescriptionLink
1Hello world — modules, interpolation, @doc and @moduledocView
2Expressions and pipes — everything returns a valueView
3Conditionals — if/unless, cond, and the case workhorseView
4Scripts that read the world — argv, env vars, and file IOView

Language Core

Immutability, matching, recursion, collections, polymorphism, errors, and binaries — the vocabulary of idiomatic Elixir.

#DescriptionLink
5Immutability — rebinding, update syntax, structural sharingView
6Pattern matching — destructuring, pin, function headsView
7Guards and with — refining matches, happy-path pipelinesView
8Functions and captures — defaults, closures, the & shorthandView
9Recursion and tail calls — body vs accumulator styleView
10Enum and Stream — eager vs lazy pipelines on the same dataView
11Comprehensions — for with generators, filters, and into:View
12Maps and structs — Access, update syntax, enforce_keysView

Protocols, Errors & Binaries

Polymorphism, failure idioms, and byte-level parsing — the three lessons that finish the language core.

#DescriptionLink
13Protocols — defprotocol/defimpl and derived implementationsView
14Behaviours — @callback contracts and @impl dispatchView
15Error handling — raise/rescue/after, tagged tuples, custom exceptionsView
16Binaries and sigils — bitstring parsing of a wire frameView

Tooling

The AST, macros, tests, and property checks — the files that teach you how Elixir compiles and verifies itself.

#DescriptionLink
17Quote and unquote — inspecting the AST of real expressionsView
18Custom macros — a trace/1 macro with hygieneView
19ExUnit and doctests — a test suite that runs in one scriptView
20Property tests — StreamData roundtrip propertiesView

Concurrency & OTP

From raw spawn to supervised servers — the phase 4 pattern book in runnable form.

#DescriptionLink
21Spawn, send, receive — a raw process with a mailboxView
22Links and monitors — crash propagation and :DOWN messagesView
23Tasks — async/await and bounded async_stream poolsView
24Agents — atomic get/update state holdersView
25GenServer — a complete key/value server with call/cast/infoView

Supervision & Shared State

Supervisors, dynamic children, registration, ETS, and telemetry — how systems stay up.

#DescriptionLink
26Supervisor — one_for_one tree with crash-loop protectionView
27DynamicSupervisor — sessions started and stopped at runtimeView
28Registry — named processes for per-user stateView
29ETS — shared read/write tables and concurrent accessView
30Telemetry — instrumenting a module with event handlersView

Ecosystem

Ecto, Broadway, Nx, and Plug — single-file scripts made runnable with Mix.install/2 (network access needed on first run).

#DescriptionLink
31Ecto changesets — schema + validation pipeline, no database requiredView
32Broadway pipeline — a custom producer with back-pressureView
33Nx tensors — defn functions and a softmaxView
34Plug pipeline — a minimal HTTP app on BanditView
35Oban worker — a job definition (study demo: needs PostgreSQL)View
36Release config — application env read from runtime.exs (study demo)View
How to run them. Stdlib demos need nothing but Elixir: 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.