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 through four stages:
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 items, then stops the pipeline
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, the pipeline terminates early without processing remaining items.
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: trace, data flow, stream, explain, investigate, pipeline