Module C1.04
The pipe & compose
Thread a value through functions, or glue the functions into one — both read left to right.
Functions transform values; the next step is to wire them together. F# offers two
operators, and the whole "F# reads top-to-bottom like a pipeline" style rests on them. The
pipe |> threads a value through a sequence of functions:
5 |> double |> inc reads "5, doubled, incremented", left to right.
Composition >> glues two functions into one new function
without naming the value at all: double >> inc is a single function you can name and
reuse. The pipe is the everyday tool; composition is the point-free refinement. This module covers both in
three dives — the pipe operator, function composition, and a real multi-stage pipeline over a list.
Two operators, one direction
The nested-call form reads inside-out: inc (double 5) asks the reader to start in
the middle and work outward. Both operators in this module fix that by putting the stages in the order they
run. They differ in what they act on — a value, or a function — and the dive selector below frames the
three lessons. Select one to read its summary and the one idea it adds.
The first dive is the pipe |>: forward application,
x |> f is exactly f x, with the value already in hand.
The second is composition >>: it merges two functions into
one for later, with no value present. The third builds a pipeline over a list —
filter, map, sum — the shape every later module reuses. Together they are why an F# program reads as a
sequence of stages rather than a stack of parentheses.
The three dives · select one
Forward application: x |> f is exactly f x. Its value is reading order — 5 |> double |> inc reads left-to-right as "5, doubled, incremented".
Open this dive · or pick another above
One operator threads a value through functions; the other glues functions into one. Both put the stages in the order they run.
The three dives
Read them in order. Each stands on valid, runnable F#: every pipe, every composition, and every result
below can be typed into dotnet fsi and produces exactly what the page shows.
The pipe operator
x |> f is f x: forward application that reads left to right. Plus the backward pipe <|.
- valuethread a value through a chain of functions
Function composition
f >> g is fun x -> g (f x): one new function, left first. The point-free refinement.
- functionglue two functions into one, name no value
Building pipelines
Chain the collection functions with |>: filter, map, sum. Name a reusable pipeline with >>.
- applya real multi-stage pipeline over a list
References
Sources
- Microsoft — F# documentation — the language guide: the pipe-forward and function-composition operators.
- FSharp.Core API reference — the operators
(|>),(<|),(>>), and(<<)as defined inOperators. - The F# Language Specification — operator definitions, fixity, and associativity.
Related in this course
- C1.04.1 — The pipe operator — forward application, step by step.
- C1.03 — Functions — the functions these operators wire together.
- Elixir — Composition — the same pipe-and-compose idea on the BEAM.