To write data from Immutable.js collections to an output stream, we set up a side-effect that iterates over the collection, writing each value to the stream. In simple cases, this is easy to do. In the more complex cases, you have to pay attention to concurrent and lazy evaluation.
Writing collection data
Iterating over collections and writing lines
Let's start by iterating over a collection and writing each value as a line to an output file:
const myList = Range()
.map(v => `Value${v}`)
.take(20)
.toList();
const output = fs.createWriteStream(
'./output/05-writing-collection-data'
);
output.on('close', () => {
console.log('done');
});
myList.forEach((v) => {
output.write((v + os...