jonnifyfsharp

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

C1.04.1 the pipe |> C1.04.2 composition >> C1.04.3 building pipelines thread a value glue functions put it to work
C1.04.1 · The pipe operator

Forward application: x |> f is exactly f x. Its value is reading order — 5 |> double |> inc reads left-to-right as "5, doubled, incremented".

You learn how |> threads a value and why the order reads forward

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.

live module hub built dive ready soon specified

References

Sources

Related in this course