What does this stream pipeline do? Trace the data flow step by step.
← Streams and Pipelines · Ref: Q987
This pipeline processes a list of order amounts in five steps:
1. cat orderAmounts — reads each Float from the list, one at a time
2. filter by isLargeOrder — keeps only amounts above the threshold, discards the rest
3. sort by compareDescending — orders the remaining amounts from largest to smallest
4. head 3 — takes only the first 3 sorted items, then stops the emission
5. > stdout — prints each of the 3 largest orders to standard output
The data flows left to right through each | operator. Each stage receives items from the previous stage and passes results to the next. The head operation acts like a limit — once 3 items have passed through, nothing more is pulled. A head stops the pull back to the nearest stage that must see everything: here that is the sort, which still has to read every large order to know which are biggest, so the filter runs on every amount; only the sorted items beyond the first 3 are never emitted. Without the sort, head 3 would stop the filter after the third large order.
Example
defines module qa.streams.explainpipeline defines function isLargeOrder() as pure -> amount as Float <- rtn as Boolean? threshold <- 100.0 rtn: amount > threshold compareDescending() as pure -> left as Float right as Float <- rtn as Integer: right <=> left defines program ExplainPipelineDemo() stdout <- Stdout() orderAmounts <- [45.99, 250.00, 89.50, 175.00, 320.00, 15.00, 199.99] stdout.println("Top 3 large orders:") cat orderAmounts | filter by isLargeOrder | sort by compareDescending | head 3 > stdout
Common mistakes
E50001 — EK9 uses Unix pipe syntax for streams, not Java method chaining. Write 'cat source | filter by fn | sort by fn | head N > stdout'.
Incorrect:
orderAmounts.stream().filter(isLargeOrder).sorted(compareDescending).limit(3).forEach(System.out::println)
Correct:
cat orderAmounts | filter by isLargeOrder | sort by compareDescending | head 3 > stdout
Other ways to ask this
- Explain what happens at each stage of this EK9 pipeline
- Walk me through how data flows through this stream
- Break down this EK9 stream pipeline for me
Coming from another language?
EK9 stream pipelines read left-to-right like Unix pipes. Each | passes data to the next operation. The > terminal sends output to a sink.
Keywords: stream, data flow, trace, pipeline, investigate, explain