What stream operations are available in EK9?
← Streams and Pipelines · Ref: Q235
EK9 stream pipelines use cat source | operations | terminal syntax. Operations fall into categories: filtering (filter, reject), transforming (map), ordering (sort), limiting (head, tail, skip), grouping (group by), flattening (flatten), deduplication (uniq), side effects (tee), and parallel execution (async). Terminals are collect as Type or > stdout.
Each operation expects a specific function type: filter uses Predicate (T to Boolean), sort uses Comparator (T, T to Integer), map uses a transform function (T to R). Use 'ek9 -h stream' for the complete reference.
Pipeline stages chain with |:
cat items | filter by pred | sort | head 5 | collect as List of T
See Q120 for sort. See Q122 for collect. See Q123 for flatten. See Q124 for group by. See Q125 for head/tail/skip. See Q133 for tee and uniq. See Q237 for streams vs loops. See Q954 for collect as custom type.
Example
defines module qa.streams.reference defines function isPositive() as pure -> num as Integer <- rtn as Boolean: num > 0 doubleIt() as pure -> num as Integer <- rtn as Integer: num * 2 intToString() as pure -> num as Integer <- rtn as String: $num defines program StreamOpsReferenceDemo() stdout <- Stdout() numbers <- [5, -3, 8, -1, 4, 8, 2, 5, -3, 10] // === FILTER BY === positives <- cat numbers | filter by isPositive | collect as List of Integer stdout.println(`filter by: ${positives}`) // === MAP WITH === doubled <- cat numbers | map with doubleIt | collect as List of Integer stdout.println(`map with: ${doubled}`) // === SORT === sorted <- cat numbers | sort | collect as List of Integer stdout.println(`sort: ${sorted}`) // === HEAD === firstThree <- cat numbers | head 3 | collect as List of Integer stdout.println(`head 3: ${firstThree}`) // === SKIP === afterFive <- cat numbers | skip 5 | collect as List of Integer stdout.println(`skip 5: ${afterFive}`) // === TAIL === lastTwo <- cat numbers | tail 2 | collect as List of Integer stdout.println(`tail 2: ${lastTwo}`) // === UNIQ (sort first) === unique <- cat numbers | sort | uniq | collect as List of Integer stdout.println(`sort + uniq: ${unique}`) // === COMBINED: filter + sort + head === topThreePositive <- cat numbers | filter by isPositive | sort | head 3 | collect as List of Integer stdout.println(`filter+sort+head: ${topThreePositive}`) // === COLLECT AS INTEGER (sum) === total <- cat numbers | filter by isPositive | collect as Integer stdout.println(`sum of positives: ${total}`) // === TEE for intermediate capture === captured <- List() of Integer result <- cat numbers | filter by isPositive | tee in captured | sort | collect as List of Integer stdout.println(`tee captured: ${captured}`) stdout.println(`final sorted: ${result}`) // === DIRECT OUTPUT === cat numbers | filter by isPositive | map with intToString > stdout
Common mistakes
E50030 — Stream filter predicates must return Boolean. A function used with 'filter by' that returns Integer instead of Boolean triggers E50030. See ek9 -h E50030 for details.
Incorrect:
<- rtn as Integer: num > 0
Correct:
<- rtn as Boolean: num > 0
Other ways to ask this
- What is the complete list of EK9 stream pipeline operations?
- What can I do in a stream pipeline in EK9?
- What are all the stream stages available in EK9?
- How do I reference all EK9 pipeline operations?
Coming from another language?
Java: Stream API (filter, map, sorted, collect). Python: list comprehensions, map(), filter(). Rust: Iterator trait (filter, map, take, collect). Go: manual loops. EK9: cat | filter | sort | head | collect, Unix pipe syntax with typed function stages.
Keywords: filter, flatten, pipeline, reject, map, migrate, collect, cat, uniq, stream, head, all, tail, group, pipe, async, reference, tee, swift, list, skip, sort, operations, complete