A pipeline turns nested calls into a top-to-bottom data journey. Each step should still be understandable and testable on its own.
Build a data pipeline with functions: full examples and further reading
The original lesson material is preserved here for reference. The main notebook focuses on this lesson's core question.
Filter, transform, and fold a list with small named steps.
Turn a list of scores into the sum of doubled passing scores.
Run this first
Run it once, change one input, and compare the new result.
%% Keep each transformation small and inspectable
Scores = [41, 60, 72],
Passing = lists:filter(fun(N) -> N >= 60 end, Scores),
Doubled = lists:map(fun(N) -> N * 2 end, Passing),
lists:foldl(fun(N, Sum) -> N + Sum end, 0, Doubled).The result is 264: (60 * 2) + (72 * 2).
Steps for the full example
- Read
lists:filter/2: Keep items for which a predicate returns true. - Read
lists:map/2: Transform every item. - Read
lists:foldl/3: Accumulate a result from left to right.
Original lesson notes
Run the example first. Predict one result, then change one input and run it again.
A higher-order function receives another function, returns one, or both.
A pipeline passes data through a sequence of small transformations.
Symbols and terms
lists:filter/2- Keep items for which a predicate returns true.
lists:map/2- Transform every item.
lists:foldl/3- Accumulate a result from left to right.
- higher-order function
- A higher-order function receives another function, returns one, or both.
- pipeline
- A pipeline passes data through a sequence of small transformations.
- fold
- A fold visits each item while carrying one accumulated result.
Original full exercise
Return the count of even numbers.
length(lists:filter(fun(N) -> N ____ 2 =:= 0 end, [1,2,3,4])).Return 2.
Show hint
Use rem for the remainder operator.
Show original answer
length(lists:filter(fun(N) -> N rem 2 =:= 0 end, [1,2,3,4])).Does this pipeline create Erlang processes?
No. These list functions run ordinary sequential transformations.
Original lesson takeaways
- Pass functions as values.
- Name intermediate data while learning.
- Use a fold when one result grows across the list.
Design trade-offs and language comparisons
Why this shape?
Why pass data through a series of small steps?
A pipe is not a superior loop. If argument order is awkward or a step hides substantial I/O, an ordinary call can be clearer.
Coming from Java, Python, or JavaScript
Java
- Familiar starting point
- Stream chains or fluent method calls.
- What BEAM changes
- Elixir
|>inserts the left value into the next call; Erlang usually nests calls or names intermediate values. - False friend
Enumis usually eager.Streamis lazy.
Python
- Familiar starting point
- Generators, comprehensions, and named intermediate values.
- What BEAM changes
- Captures and pipes compose small functions without mutating a list.
- False friend
&String.trim/1is a function value;String.trim/1only names a function and arity.
JavaScript
- Familiar starting point
- map/filter chains, callbacks, and iterators.
- What BEAM changes
- Values are immutable by default; each step returns another result.
- False friend
- Do not read
&1as JavaScript's bitwise ampersand.