Write a function that transforms a list of names to uppercase.
← Streams and Pipelines · Ref: Q1034
Use a stream pipeline with map to transform each item:
uppercased <- cat names | map with toUpper | collect as List of String
The 'map with' operation applies a function to each item in the stream. The function must take one argument and return one value.
Define the transformation as a named pure function:
toUpper() as pure -> name as String <- rtn as String: name.upperCase()
Then use it in the pipeline. This is cleaner than a loop because:
- The intent is clear: transform each item
- The function is testable on its own
- No mutable accumulator needed
For output instead of collecting:
cat names | map with toUpper > stdout
Example
defines module qa.streams.codertransform defines function toUpper() as pure -> name as String <- rtn as String: name.upperCase() addGreeting() as pure -> name as String <- rtn as String: "Hello, " + name defines program StreamTransformDemo() stdout <- Stdout() names <- ["alice", "bob", "charlie"] //Transform to uppercase uppercased <- cat names | map with toUpper | collect as List of String stdout.println(`Uppercased: ${uppercased}`) //Chain transformations cat names | map with toUpper | map with addGreeting > stdout
Common mistakes
E01010 — EK9 streams use pipe syntax with named functions. Write 'cat source | map with functionName | collect as Type'.
Incorrect:
uppercased <- names.map(n -> n.upperCase())
Correct:
uppercased <- cat names | map with toUpper | collect as List of String
Other ways to ask this
- How do I map a list of strings to uppercase in EK9?
- Write code to convert all items in a list using a stream
- Show me how to use map with in a stream pipeline
Coming from another language?
EK9 uses 'cat source | map with fn | collect as Type' for list transformations. Named functions replace lambdas.
Keywords: map, stream, coder, transform, pipeline, uppercase