jonnifyelixir
Course / F2 · Functional Programming

Chapter F2 · nine modules

Functional Programming

F1 showed that functions are an algebra. This chapter takes that algebra off the page and makes it the working style of Elixir: pure transformations of immutable data, composed into programs.

Every idea here has a root in F1 — substitution becomes purity, immutable binding becomes persistent data, composition becomes the pipe, and the higher-order operators become the everyday verbs of the language. The path runs from what a functional value is, through the operators that act on collections, to composing whole programs, and ends in a lab where a dataset flows through a pipeline you build.

data pure f pure g result

The arc of the chapter

Nine modules in four movements. Foundations fix what a functional value is — pure and persistent. The operators are the verbs that act on collections: higher-order functions, recursion, and folds. Abstraction builds larger structures — closures, algebraic data types, and composition. The lab puts it together over a real dataset.

Select a stop on the path to see what it covers.

The journey · select a module

FOUNDATIONS THE OPERATORS ABSTRACTION THE LAB 1 pure 2 persist 3 higher-order 4 recursion 5 folds 6 closures 7 ADTs 8 compose 9 lab start here lab
Pure functions & side effects

What purity buys, and how to keep it: deterministic results and isolated effects.

F2.01 · module Foundations available now

The chapter is a single line of reasoning: settle what a value is, learn the verbs that act on it, then compose those verbs into programs.

The shape of a functional program

Most functional programs have one shape: data enters, flows through a series of pure transformations, and a result comes out. Each stage is a function; the pipe threads them together. Toggle the stages and watch a list move through the pipeline — the destination this chapter builds toward.

A pipeline · data through pure stages



      
[1, 2, 3, 4, 5, 6] → map → filter → reduce → 30

F1 · Algebra

Composition: applying one function after another, the pipe written in evaluation order.

F2 · Functional

A program is a pipeline of pure transformations — data |> map |> filter |> reduce.

If each stage is pure, the whole pipeline is pure: the same input always gives the same output, and you can read it one stage at a time.

The nine modules

Foundations

F2.01 · Pure functions & side effects — start here
What purity buys; isolating effects.
F2.02 · Immutability & persistent data — available
Structural sharing; why copying is cheap.

The operators

F2.03 · Higher-order functions — available
Functions as arguments and return values.
F2.04 · Recursion patterns & tail calls — available
Accumulators and tail-call optimisation.
F2.05 · map / filter / reduce (folds) — available
reduce as the universal fold.

Abstraction

F2.06 · Closures & partial application — available
Capturing environment; the capture operator and currying by hand.
F2.07 · Algebraic data types — available
Sum and product types; tagged tuples.
F2.08 · Composition & pipelines — available
Building programs by composing functions.

The lab

F2.09 · The data-pipeline lab — available
Compose map / filter / reduce over a dataset; watch each stage.

Where this sits

F2 is the second of six chapters. It follows F1 · Algebra, which established functions, composition, and the higher-order operators as mathematics; it precedes F3 · The Elixir Language, which grounds these ideas in syntax, modules, and tooling, and F4 · Algorithms & Data Structures, where persistent structures and folds do real work. Read in order, each chapter is a consequence of the one before.

Begin with F2.01 — Pure functions & side effects, the foundation the rest of the chapter rests on.