consoleOut

@ExperimentalCoroutinesApi
fun <T : Any> Flow<T>.consoleOut(dispatcher: CoroutineDispatcher = Dispatchers.IO.limitedParallelism(1), print: Print = Print.BREAK_LINE, mapper: suspend (T) -> Pair<Any, OutType> = { it to OutType.DEFAULT }): Flow<Pair<Any, OutType>>

Outputs the flow of objects to the console (stdout or stderr) using the specified dispatcher, print, and mapper.

Return

The original flow of objects.

Example usage:

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

peopleFlow.consoleOut().collect()

Parameters

dispatcher

The CoroutineDispatcher to use for writing to the console. Defaults to a single-threaded dispatcher.

print

The print mode (Print.BREAK_LINE or Print.NO_BREAK) to use for console output.

mapper

A function that maps each object in the flow to a pair of (output item, output type). Defaults to the original item and OutType.DEFAULT.