Why must stream functions have exactly one parameter in EK9?
← Streams and Pipelines · Ref: Q824
EK9 stream operators like filter, uniq, sort, and map require functions with exactly one parameter matching the stream element type.
THE RULE
Stream pipeline functions must have a single parameter:
isPositive() as pure -> amount as Integer // ONE parameter: correct <- rtn as Boolean: amount > 0
A function with zero or multiple parameters triggers E07460:
isInRange() as pure -> lo as Integer // TWO parameters: wrong -> hi as Integer <- rtn as Boolean: true
WHY THIS RULE
Stream operators call the function once per element, passing the current element as the single argument. A function with 0 or 2+ parameters cannot receive a single stream element.
HOW TO FIX
- Use a single parameter matching the stream type
- If you need additional context, use a dynamic function that captures extra values
See Q812 for stream errors. See Q126 for stream reference.
Example
defines module qa.streams.function.arity defines function isPositive() as pure -> amount as Integer <- rtn as Boolean: amount > 0 isInRange() as pure -> lowerBound as Integer upperBound as Integer <- rtn as Boolean: lowerBound < upperBound defines program StreamFunctionArityDemo() stdout <- Stdout() // === CORRECT: filter with single-parameter predicate === cat [3, -1, 5, -2, 8] | filter by isPositive > stdout
Common mistakes
E07460 — Stream uniq requires a function with exactly one parameter matching the stream type. isInRange has two parameters so cannot receive a single stream element. See ek9 -h E07460 for details.
Incorrect:
| uniq isInRange
Correct:
| filter by isPositive
Other ways to ask this
- What is E07460 FUNCTION_MUST_HAVE_SINGLE_PARAMETER?
- Why does my stream filter function fail with parameter count error?
- How many parameters can a stream function have in EK9?
Coming from another language?
Java: Stream.filter() takes Predicate<T> (single arg). Python: filter(func, iterable) passes one item. Rust: .filter(|x| ...) takes one reference. Go: no built-in stream, but range gives one item. EK9: compile-time enforcement that stream functions have exactly one parameter.
Keywords: sort, uniq, function, single, stream, arity, filter, parameter, E07460