-
Notifications
You must be signed in to change notification settings - Fork 0
Section 2 Lesson 23: The Pipe Operator
Thiago Salles edited this page Jul 1, 2021
·
1 revision
The pipe operator |>
passes the result of an expression as the first parameter of another expression.
It’s similar to the Unix | operator.
Its purpose is to highlight the data being transformed by a series of functions.
To see how it can make the code cleaner, have a look at this code:
Enum.sum(Enum.filter(Enum.map(1..100_000, &(&1 * 3)), odd?))
That's the same code rewritten using the |>
operator:
1..100_000
|> Enum.map(&(&1 * 3))
|> Enum.filter(odd?)
|> Enum.sum()
More to read:
Section 1: An Elixir Warmup
5 - Generating a Project
6 - Modules and Methods
7 - Lists and Strings
8 - Method Arguments
11 - Immutability
13 - Comprehensions Over Lists
Section 2: Pattern Matching
17 - Overview
18 - Relationship with Erlang
23 - The Pipe Operator
24 - Installing Dependencies
Section 3: Testing and Documentation
Section 4: A Few Side Topics