resource

fun <A> resource(block: suspend ResourceScope.() -> A): Resource<A>


fun <A> resource(acquire: suspend () -> A, release: suspend (A, ExitCase) -> Unit): Resource<A>

Construct a Resource from an allocating function acquire and a release function release.

import arrow.fx.coroutines.resource
import arrow.fx.coroutines.resourceScope

val resource = resource {
install({ 42.also { println("Getting expensive resource") } }) { r, exitCase ->
println("Releasing expensive resource: $r, exit: $exitCase")
}
}

suspend fun main(): Unit = resourceScope {
val res = resource.bind()
println("Expensive resource under use! $res")
}