liveBook · Manning

Pipe operator

As explained in F# in Action: A Revised Edition of Get Programming with F#

The F# pipeline operator (|>) passes the value of its left-hand expression as an argument to the function on its right.

The F# pipe operator (|>) passes the value on its left to the last argument of the function on its right. It lets data flow through a readable sequence of transformations. section 6.1.3

Use the pipe operator to remove temporary variables and avoid reversing the conceptual flow with nested calls:

  • Direct call: addFive 10 becomes 10 |> addFive. section 6.1.3
  • Multiple transformations can be chained when one function’s output matches the next function’s input. section 6.1.3
  • Pipelines can be formatted on one line or across multiple lines. section 6.1.3

A small numeric pipeline

let pipelineMultiline = 10 |> add 5 |> add 7 |> multiply 2 This expresses the same calculation as nested calls, but follows the value from left to right. section 6.1.3

Listing 6.4 Chaining function calls using the pipeline operator
let pipelineSingleLine = 10 |> add 5 |> add 7 |> multiply 2   #1
 
let pipelineMultiline =                                       #2
    10
    |> add 5
    |> add 7
    |> multiply 2

Compare single-line and multiline pipeline syntax in a complete F# listing. section 6.1.3

How F# in Action: A Revised Edition of Get Programming with F# covers it

How deep it goes
Defines argument placement, chaining, and formatting, but stops short of deeper implementation details.
Examples
Uses arithmetic transformations and a fictional customer email workflow as pipeline examples.
What it assumes
Assumes familiarity with F# function calls and multiple arguments while clarifying how the final argument moves across the pipe.
What you can do after
Apply it to replace temporary variables and nested calls with readable single-line or multiline F# pipelines.
How it connects
Connects function composition, currying, nested function calls, and data transformation pipelines.

Also explained in

Compare how 6 books explain pipe operator →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of F# in Action: A Revised Edition of Get Programming with F#. The section links point to the parts of the book it draws on.