closeable

suspend fun <A : Closeable> ResourceScope.closeable(closingDispatcher: CoroutineDispatcher = Dispatchers.IO, closeable: suspend () -> A): A(source)

Creates a Resource from an Closeable, which uses Closeable.close for releasing.

import arrow.fx.coroutines.resourceScope
import arrow.fx.coroutines.closeable
import java.io.FileInputStream

suspend fun copyFile(src: String, dest: String): Unit =
resourceScope {
val a: FileInputStream = closeable { FileInputStream(src) }
val b: FileInputStream = closeable { FileInputStream(dest) }
/** read from `a` and write to `b`. **/
} // Both resources will be closed accordingly to their #close methods

fun <A : Closeable> closeable(closingDispatcher: CoroutineDispatcher = Dispatchers.IO, closeable: suspend () -> A): Resource<A>(source)