Show me the simplest possible stream pipeline that outputs to stdout in EK9.

← Streams and Pipelines · Ref: Q1002

The simplest pipeline reads a collection and sends it to stdout:

  cat items > stdout

That reads every item from 'items' and prints each to standard output. Like Unix: cat file > output.

ADD A FILTER:

  cat items | filter by isValid > stdout

Keeps only items where isValid returns true.

ADD A TRANSFORM:

  cat items | map with transform > stdout

Applies 'transform' to each item before output.

COLLECT INSTEAD OF OUTPUT:

  results <- cat items | filter by isValid | collect as List of String

Gathers filtered items into a new List instead of printing them.

The | operator passes data from one stage to the next. The > operator sends the final result to a sink (stdout, a file, or any type with operator |).

Example

defines module qa.streams.firstpipeline

  defines function

    isLongEnough() as pure
      -> word as String
      <- rtn as Boolean?

      minimumLength <- 3
      rtn: word.length() > minimumLength

  defines program

    FirstPipelineDemo()
      stdout <- Stdout()

      names <- ["Alice", "Bob", "Charlie", "Di", "Eve", "Frank"]

      // Simplest pipeline: cat > stdout
      stdout.println("All names:")
      cat names > stdout

      // With filter
      stdout.println("Long names:")
      cat names | filter by isLongEnough > stdout

      // Collect into a new list
      longNames <- cat names
        | filter by isLongEnough
        | collect as List of String
      stdout.println(`Collected: ${longNames}`)

Common mistakes

E50001 — EK9 streams use pipe syntax, not method chaining. Write 'cat collection > stdout' to print all items.

Incorrect:

      names.forEach(stdout::println)

Correct:

      cat names > stdout
Other ways to ask this
  • What is the most basic stream pipeline in EK9?
  • How do I get started with EK9 streams?
  • Show me cat and > stdout in EK9

Coming from another language?

EK9 streams use Unix pipe syntax: cat source | operation | operation > sink. The > terminal replaces forEach/println loops.

Keywords: stream, pipeline, first, cat, beginner, basic, stdout