Why must functions used with stream call take zero arguments?

← Streams and Pipelines · Ref: Q867

Functions used with call in a stream pipeline must take ZERO arguments. The stream invokes them without parameters — they act as suppliers.

CORRECT PATTERN

  getGreeting()
    <- rtn <- "Hello EK9"
  cat [getGreeting] | call > collector

Zero-argument function that returns a value.

INCORRECT PATTERN

  needsArg()
    -> prefix as String
    <- rtn <- "Hello EK9"
  cat [needsArg] | call > collector

The function takes a parameter — the stream has no way to supply it.

See Q844 for call argument rules. See Q843 for return requirement.

Example

defines module qa.streams.call.zero.args

  defines function

    getGreeting()
      <- rtn <- "Hello EK9"

    needsArg()
      -> prefix as String
      <- rtn as String: prefix

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

  defines function

    StreamZeroArgsDemo()
      collector <- StringCollector()
      cat [getGreeting] | call > collector
      require collector?

Common mistakes

E06310 — Functions used with stream call must take no arguments. The function needsArg requires a parameter the stream cannot supply. Use a zero-argument function. See ek9 -h E06310 for details.

Incorrect:

      cat [needsArg] | call > collector

Correct:

      cat [getGreeting] | call > collector
Other ways to ask this
  • What triggers E06310 REQUIRE_NO_ARGUMENTS in streams?
  • Why can't I stream a function that takes parameters through call?
  • What is the correct function shape for stream call?

Coming from another language?

Java: Supplier has get() with no arguments. Python: zero-arg callables used with map/filter. EK9: call requires zero-argument supplier functions.

Keywords: E06310, arguments, pipeline, stream, call, supplier, function, zero