Why does EK9 report E06330 when using a function with the wrong type in a stream pipeline?
← Streams and Pipelines · Ref: Q885
Stream pipeline operations require functions whose parameter types match the current stream element type. When you use `uniq` with a function that accepts a different type, the compiler raises E06330.
TYPE MATCHING IN PIPELINES
Each pipeline stage knows the current stream type. A function used with uniq must accept the stream element type:
cat [1, 2, 3] | uniq hashInteger | ... // Correct: hashInteger takes Integer cat [1, 2, 3] | uniq hashString | ... // ERROR: hashString takes String
WHY ENFORCED
A type mismatch in a pipeline would produce a runtime ClassCastException in Java. EK9 catches this at compile time by validating that each function's parameter type matches the stream type at that stage.
See Q235 for stream operations reference. See Q237 for streams vs loops. See Q857 for split predicate requirements.
Example
defines module qa.streams.typemismatch defines function <?- Hash function for Integer — matches stream of Integer. -?> hashInteger() as pure -> item as Integer <- rtn as Integer: #? item <?- Hash function for String — does NOT match stream of Integer. Exists to demonstrate the type mismatch. -?> hashString() as pure -> item as String <- rtn as Integer: #? item defines program StreamTypeMismatchDemo() stdout <- Stdout() collection <- cat [1, 2, 3, 2, 1] | uniq hashInteger | collect as List of Integer stdout.println(`Unique count: ${length collection}`)
Common mistakes
E06330 — The function hashString takes a String parameter, but the stream contains Integer elements. Use a function whose parameter type matches the stream element type. See ek9 -h E06330 for details.
Incorrect:
uniq hashString
Correct:
uniq hashInteger
Other ways to ask this
- What triggers E06330 INCOMPATIBLE_TYPE_ARGUMENTS in streams?
- Why must stream function parameter types match the stream element type?
- What happens when a uniq function takes the wrong type?
Coming from another language?
Java: Stream type mismatches produce verbose generic errors. Python: map/filter type mismatches caught at runtime only. Go: strict typing on range functions. Rust: iterator adaptor trait bounds checked at compile time. EK9: per-operation type validation with clear error messages.
Keywords: parameter, uniq, incompatible, E06330, argument, mismatch, stream, pipeline, function, type