Why must functions used with stream call return a value?

← Streams and Pipelines · Ref: Q866

Functions used with call in a stream pipeline must return a value. The return value becomes the next element flowing downstream. A void function produces nothing, breaking the pipeline.

CORRECT PATTERN

  getSteve()
    <- rtn <- "Steve"
  cat [getSteve] | call > collector

The function returns a String, which flows into the collector.

INCORRECT PATTERN

  doesNotReturn()
    require true
  cat [doesNotReturn] | call > collector

The void function produces nothing — the pipeline has no elements to collect.

See Q843 for function return requirement. See Q813 for call/async rules.

Example

defines module qa.streams.call.void.function

  defines function

    getSteve()
      <- rtn <- "Steve"

    doesNotReturn()
      require true

  defines class
    StringCollector
      received <- String()
      operator |
        -> item as String
        if item?
          received: String(item)
      override operator ? as pure
        <- rtn as Boolean: received?

  defines function

    StreamCallDemo()
      collector <- StringCollector()
      cat [getSteve] | call > collector
      require collector?

Common mistakes

E07490 — Functions used with stream call must return a value. The void function doesNotReturn produces nothing for the pipeline. Use a function that returns a value. See ek9 -h E07490 for details.

Incorrect:

      cat [doesNotReturn] | call > collector

Correct:

      cat [getSteve] | call > collector
Other ways to ask this
  • What triggers E07490 FUNCTION_MUST_RETURN_VALUE in streams?
  • Why can't I use a void function with cat and call?
  • What happens when a function in a stream pipeline returns nothing?

Coming from another language?

Java: Supplier returns T, Runnable returns void — Stream.generate requires Supplier. Python: map expects return values. EK9: call requires supplier-style functions that return a value.

Keywords: void, pipeline, return, stream, E07490, call, supplier, function