parseCsv

fun Flow<String>.parseCsv(delimiter: String = ";"): Flow<List<String>>

Parses the CSV data from a flow of strings and emits each row as a list of strings.

Return

A flow of lists of strings, each representing a row of parsed CSV values.

Example usage:

val csvFlow = flowOf("Name;Age", "Alice;30", "Bob;25")
csvFlow.parseCsv().collect { row -> println(row) }

Parameters

delimiter

The delimiter to use for separating values in the CSV. Defaults to ";".


fun <T> Flow<String>.parseCsv(delimiter: String = ";", f: (List<String>) -> T): Flow<T>

Parses the CSV data from a flow of strings and emits each row as a custom object, converted using the provided function.

Return

A flow of custom objects, each representing a row of parsed CSV values.

Example usage:

data class Person(val name: String, val age: Int)

val csvFlow = flowOf("Name;Age", "Alice;30", "Bob;25")

csvFlow
.parseCsv { (name, age) -> Person(name, age.toInt()) }
.collect { person -> println(person) }

Parameters

delimiter

The delimiter to use for separating values in the CSV. Defaults to ";".

f

The function to convert the parsed row (list of strings) into a custom object.