Jun Sekine
05/06/2026, 6:18 PMCLOVIS
05/07/2026, 7:58 AMFlow instead of Sequence ?
Sequences can't be closed, so they're often not very convenient for IO-related streaming. For example if you stream from a database, you need to close the cursor when you're done, and Sequence doesn't provide a way to do that.Jun Sekine
05/07/2026, 9:27 AMFlow instead of Sequence ?
To be honest, I wanted to build the core parts, such as the parser, using only the standard library, so I have not deeply considered whether to use Flow as an option.
Your point that Flow is better suited for composition with files or DBIO, cancellation, and asynchronous processing is valid. On the other hand, as the original implementation was, the CsvReader and CsvWriter classes in this PR are designed as pure synchronous CSV converters that do not own I/O (excluding extension functions).
As for the lifecycle of file handles, I have encapsulated them within a read(path) { rows -> ... } block API. However, considering the connectivity with DBIO and asynchronous streams, I thought it might be worth considering support for Flow.
/**
* Read CSV rows from [source] (UTF-8) and pass them to [block].
* [source] is caller-owned — this function does not close it. The `Sequence`
* passed to [block] must be consumed inside the block.
*/
fun <T> CsvReader.read(
source: Source,
options: CsvReadIoOptions = CsvReadIoOptions(),
block: (Sequence<List<String>>) -> T,
): T = block(read(source.toCharSequence(options.stripBom)))