alsoAppendTo

suspend fun <T> Flow<T>.alsoAppendTo(    file: Path,     vararg options: OpenOption = arrayOf( StandardOpenOption.WRITE, StandardOpenOption.CREATE ),     mapper: suspend (T) -> ByteArray): Flow<T>

Transforms the content of this Flow of type T using the given mapper to a Flow of ByteArrays, then appends the ByteArrays to the specified file while also returning the original content.

Return

A Flow of type T representing the original content.

Example usage:

val file: Path = ...
val stringFlow: Flow<String> = ...
stringFlow
    .alsoAppendTo(file) { string -> string.toByteArray() }
    .collect { originalString -> ... }

Parameters

file

The file path to append to.

options

The options specifying how the file is opened. Defaults to StandardOpenOption.WRITE and StandardOpenOption.CREATE.

mapper

A function to transform items of type T to ByteArray.