Capture intermediate sorted results into a side list using tee.
← Streams and Pipelines · Ref: Q1140
tee copies items to a side list without disrupting the pipeline:
cat items | sort | tee in sideList | head 3 > stdout
sideList gets all sorted items; the main pipeline continues to head 3. See Q980, Q1138.
Example
defines module qa.streams.streamteecapture defines program StreamTeeCaptureDemo() stdout <- Stdout() sideList <- List() of Integer //Tee captures sorted items before head truncates stdout.println("Pipeline output (head 3):") cat [5, 3, 1, 4, 2] | sort | tee in sideList | head 3 > stdout //Side list has ALL sorted items, not just head 3 stdout.println("Side captured (all sorted):") cat sideList > stdout
Other ways to ask this
- I need to save a snapshot of the stream at a mid-pipeline stage
- In Unix I'd use tee to copy output to a file while continuing the pipeline. Show the EK9 tee
- Given a sort | head pipeline, capture the sorted items before head truncates them
- Tap into a stream pipeline to collect intermediate results without disrupting flow
Coming from another language?
Unix: cmd | tee file.txt | next. Java: peek() in streams. EK9: | tee in list | continues pipeline.
Keywords: snapshot, tee, intermediate, tap, side list, capture