rawCsv

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

Converts a flow of objects into a flow of raw CSV strings, using a provided function to convert each object into a list of strings.

Return

A flow of raw CSV strings.

Example usage:

data class Person(val name: String, val age: Int)
val peopleFlow = flowOf(Person("Alice", 30), Person("Bob", 25))

peopleFlow
.rawCsv(listOf("Name", "Age"), delimiter = ";") { person ->
listOf(person.name, person.age.toString())
}
.collect { line -> println(line) }

Parameters

headers

The list of header names for the CSV.

delimiter

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

f

The function to convert each object into a list of strings.


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

Converts a flow of objects into a flow of raw CSV strings, using a provided function to convert each object into a list of strings.

Return

A flow of raw CSV strings.

Example usage:

data class Person(val name: String, val age: Int)
val peopleFlow = flowOf(Person("Alice", 30), Person("Bob", 25))

peopleFlow
.rawCsv("Name", "Age", delimiter = ";") { person ->
listOf(person.name, person.age.toString())
}
.collect { line -> println(line) }

Parameters

headers

The vararg of header names for the CSV.

delimiter

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

f

The function to convert each object into a list of strings.