E10020: Void cannot be used in stream pipelines
What went wrong
Void cannot be used in stream pipelines. Stream operations pass values from one stage to the next, but Void has no value to pass.
Worked examples
Compilable examples demonstrating this error and the correct fix:
- ek9 -q 928 (Why can't I use a void function in a stream pipeline i...)
Stream operation requirements
- 'map' - function must have return value
- 'filter' - function must return Boolean
- 'tee' - takes a target that keeps or writes the items (a collection, 'stdout'), not a function
- 'collect' - must specify collection type
How to fix it
- If using 'map', ensure the function has a returning variable
- If the function is for side effects only, it does not belong in a pipeline: iterate with 'for item in values' and call it for each item (a void function is not a pipeline sink or 'tee' target either)
- Check that mapping function signature matches stream type
The [EXAMPLE] section below shows a void function mapped and collected 'as Void', and a function that returns the upper-cased String mapped and collected as a List.
See also
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E10020: Void cannot be used in stream pipelines
#!ek9 defines module error.e10020.bad defines function voidFunction() -> item as String require item? //No return mainValue - returns Void testStreamWithVoid() values <- ["a", "b", "c"] result <- cat values | map voidFunction | collect as Void
Fixed: Give each stage a function that returns a value
#!ek9 defines module error.e10020.good defines function shout() as pure -> item as String <- rtn as String: item.upperCase() testStream() <- rtn as List of String: List() values <- ["a", "b", "c"] rtn: cat values | map shout | collect as List of String