asFlow

fun <A> Resource<A>.asFlow(): Flow<A>(source)

Runs Resource.use and emits A of the resource

import arrow.fx.coroutines.*

fun Flow<ByteArray>.writeAll(path: Path): Flow<Unit> =
Resource.fromCloseable { path.toFile().outputStream() }
.asFlow()
.flatMapConcat { writer -> byteFlow.map { writer.write(it) } }
.flowOn(Dispatchers.IO)

fun Path.readAll(): Flow<String> = flow {
path.useLines { lines -> emitAll(lines) }
}

Path("example.kt")
.readAll()
.