What do tail and skip do in EK9 stream pipelines?
← Streams and Pipelines · Ref: Q931
Tail keeps the last N elements. Skip discards the first N elements. Both are positional operations in the pipeline.
TAIL N
Keeps only the final N elements that flow through the stream:
cat [1, 2, 3, 4, 5] | tail 2 | collect as List of Integer Result: [4, 5]
SKIP N
Discards the first N elements, passing the rest downstream:
cat [1, 2, 3, 4, 5] | skip 2 | collect as List of Integer Result: [3, 4, 5]
COMBINED
Skip the first 2, then take only the last 2 of what remains:
cat [1, 2, 3, 4, 5, 6] | skip 2 | tail 2 | collect as List of Integer Result: [5, 6] (skip gives [3,4,5,6], tail 2 gives [5,6])
Think of skip as Unix 'tail -n +N' and tail as Unix 'tail -N'.
See Q235 for all stream operations. See Q125 for head/tail/skip. See Q896 for redirect. See Q954 for collect as custom type.
Example
defines module qa.streams.tail.skip.example defines program TailSkipDemo() stdout <- Stdout() values <- [10, 20, 30, 40, 50, 60, 70] //Demonstrate list operations that mirror tail and skip concepts stdout.println(`Full list: ${values}`) stdout.println(`List length: ${length values}`) //Access elements by index using getOrDefault defaultVal <- 0 firstElement <- values.getOrDefault(0, defaultVal) if firstElement? stdout.println(`First element: ${firstElement}`) lastIndex <- length values - 1 lastElement <- values.getOrDefault(lastIndex, defaultVal) if lastElement? stdout.println(`Last element: ${lastElement}`)
Other ways to ask this
- How do I get the last N elements from a stream in EK9?
- How do I skip elements at the start of an EK9 stream?
- Can I combine tail and skip in EK9?
Coming from another language?
Java: stream().skip(n) and no direct tail — need collect then subList. Python: islice(iter, n, None) for skip, deque(iter, maxlen=n) for tail. Rust: iter().skip(n) and no direct last-n. Go: manual slicing. EK9: skip N and tail N as built-in pipeline stages.
Keywords: tail, stream, skip, pipeline, discard, positional, last