A List cannot be appended to while it is being read: read a copy, or replace it with '>'
The complete source of streamsAndPipelines_sink_not_itself.ek9, compiled by the EK9 compiler. Shown on streamsAndPipelines.html.
#!ek9 defines module site.streamsAndPipelines.sink.not.itself defines program SinkNotItselfDemo() stdout <- Stdout() //'cat numbers >> numbers' is E08277: '>>' would add to the List while 'cat' is still reading it. //Read a copy and append that. numbers <- [1, 2, 3] copy <- List() of Integer copy += numbers cat copy >> numbers stdout.println(`appended: ${numbers}`) //'>' fills a fresh List and swaps it in when the stream is finished, so reading what it held is fine. cat numbers | head 3 > numbers stdout.println(`replaced: ${numbers}`)
Download streamsAndPipelines_sink_not_itself.ek9
Output
appended: [1, 2, 3, 1, 2, 3] replaced: [1, 2, 3]