Skip to content

Elixir Pipe Operator — Data Transformation Pipelines

DodaTech Updated 2026-06-29 1 min read

In this tutorial, you will learn about Elixir Pipe Operator. We cover key concepts, practical examples, and best practices to help you master this topic.

The pipe operator |> is Elixir's secret weapon for readable code. It takes the result of the left expression and passes it as the first argument to the right function. This lets you Express data transformations as a linear pipeline — read from top to bottom.

In this tutorial, you'll master the pipe operator, a hallmark of idiomatic Elixir.

Basic Piping

# Without pipe (nested, reads inside-out):
String.capitalize(String.trim("  hello world  "))
# => "Hello World"

# With pipe (reads top-down):
"  hello world  "
|> String.trim()
|> String.capitalize()
# => "Hello World"

Pattern

# Each step transforms the data
[1, 2, 3, 4, 5, 6]
|> Enum.filter(&(rem(&1, 2) == 0))    # [2, 4, 6]
|> Enum.map(&(&1 * 10))               # [20, 40, 60]
|> Enum.join(", ")                      # "20, 40, 60"

# Real-world: process user data
users
|> Enum.filter(& &1.active)
|> Enum.map(& &1.name)
|> Enum.sort()
|> Enum.join(", ")

Capture with Pipes

# Using capture operator in pipes
[1, 2, 3]
|> Enum.map(&(&1 * 2))       # Captures: fn x -> x * 2 end
|> Enum.filter(&(&1 > 3))    # Captures: fn x -> x > 3 end
|> Enum.reduce(&+/2)          # Captures: fn a, b -> a + b end (sum)

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro