Why does streaming non-function values through call fail with E04040?

← Streams and Pipelines · Ref: Q842

The stream call and async operators execute function delegates flowing through the pipeline. If the stream contains non-function values (integers, strings), they cannot be 'called' and the compiler rejects with E04040.

See Q813 for call/async rules.

Example

defines module qa.streams.call.requires.function

  defines function

    getGreeting()
      <- rtn <- "Hello"

    getFarewell()
      <- rtn <- "Goodbye"

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

  defines function

    StreamCallDemo()
      collector <- StreamSink()
      cat [getGreeting, getFarewell] | call > collector
      require collector?

Common mistakes

E04040 — Stream call requires function delegates, not integer values. See ek9 -h E04040 for details.

Incorrect:

      cat [1, 2, 3] | call > collector

Correct:

      cat [getGreeting, getFarewell] | call > collector
Other ways to ask this
  • What triggers E04040 TYPE_MUST_BE_FUNCTION?
  • Why can't I use cat [1, 2, 3] | call in EK9?
  • What types can flow through call in an EK9 stream?

Coming from another language?

Java: no built-in call operator. Python: map(func, iterable). EK9: call/async require function delegates as stream elements.

Keywords: function, stream, call, E04040, pipeline, type, delegate