I have a computation that calculates rows of data, let’s say they are NamedTuples with the same keys. I would like to emit this into a CSV file without collecting or making it an iterable.
Why?
Why not collect? The data is large. Why not wrap in an iterable? The algorithm is such that it is easier to pass around a sink to which one writes to, than concatenate many layers of iterators.
Pseudocode for what I want:
sink = make_csv_sink(path, schema::Type{<:NamedTuple{colnames}})
emit(sink, a_namedtuple) # checking that colnames match would be nice
close(sink)
When the fields are numbers or unescaped strings, this can be trivially implemented, but if we get into fancier CSV escapes it becomes tricky. This question has been asked before without a solution.
Existing CSV libraries must have this functionality (or the building blocks for it), but it is not exposed.