Card 01/ 10
All 10 cards
ConceptDifficulty: Intermediate1 min
A Pipeline That Does Nothing at All Until Something Asks for a Result
Four lines that filter, transform and print a list. They run without error, print nothing, and take no measurable time.
invoices.stream()
.filter(i -> i.pence() > 10_000)
.map(Invoice::reference)
.peek(System.out::println);Nothing ran. A stream operation like filter or map does not do any work — it records that the work should happen and returns a new stream. The pipeline is a description, and a description executes nothing.
| Kind | Returns | Runs the pipeline | Examples |
|---|---|---|---|
| Intermediate | Another stream | No | filter, map, sorted, limit, distinct |
| Terminal | A value, or nothing | Yes | collect, forEach, count, findFirst, reduce |
There is no terminal operation in the listing, so the description was built and discarded. Replacing peek with forEach makes it print, because forEach is terminal and terminal operations are what make anything happen.
So the shape of every pipeline is the same: a source, some description, and exactly one thing at the end that asks for a result. If nothing happened, look at the last line first.