How do reject and tee work in EK9 stream pipelines?

← Streams and Pipelines · Ref: Q980

reject is the inverse of filter — it removes matching items.
tee copies items to a side collection while continuing the pipeline.

  cat items | reject by isBlank | tee in backup | head 5 > stdout

reject by predicate: removes items where predicate returns true (opposite of filter by).
tee in collection: copies each item into the collection AND continues the pipeline.

Example

defines module qa.streams.rejecttee

  defines function

    isBelowThreshold() as pure
      -> measurement as Float
      <- rtn as Boolean?

      minimumReading <- 10.0
      rtn: measurement < minimumReading

  defines program

    RejectTeeDemo()
      stdout <- Stdout()

      readings <- [5.2, 15.8, 3.1, 22.4, 9.7, 18.3, 7.0]

      validReadings <- List() of Float

      stdout.println("Valid readings (above threshold):")
      cat readings
        | reject by isBelowThreshold
        | tee in validReadings
        > stdout

      stdout.println(`Saved ${validReadings.length()} valid readings`)

Common mistakes

E01010 — Use 'reject by' to remove matching items. 'filter by not' is not valid syntax. reject is the inverse of filter.

Incorrect:

      cat readings
        | filter by not isBelowThreshold
        > stdout

Correct:

      cat readings
        | reject by isBelowThreshold
        | tee in validReadings
        > stdout
Other ways to ask this
  • What is the opposite of filter in an EK9 stream?
  • How do I copy stream items to a side collection while continuing the pipeline?
  • Show me tee in an EK9 stream

Coming from another language?

Java: no reject (use filter with negation). No tee (use peek with side-effect). EK9: reject is first-class, tee is explicit side-copy.

Keywords: pipeline, reject, side copy, tee, stream