com.thoughtworks.raii.covariant
The data structure that provides automatic resource management.
ResourceT can be used as a monad transformer for scalaz.Name
ResourceT
import scalaz.Name import com.thoughtworks.raii.covariant._ type RAII[A] = ResourceT[Name, A]
Given a resource that creates temporary files
import java.io.File val resource: RAII[File] = ResourceT(Name(new Resource[Name, File] { override val value: File = File.createTempFile("test", ".tmp"); override val release: Name[Unit] = Name { val isDeleted = value.delete() } }))
when using temporary file created by resouce in a for / yield block, those temporary files should be available.
resouce
for
yield
import scalaz.syntax.all._ val usingResouce = for { tmpFile1 <- resource tmpFile2 <- resource } yield { tmpFile1 shouldNot be(tmpFile2) tmpFile1 should exist tmpFile2 should exist (tmpFile1, tmpFile2) }
and those files should have been deleted after the for / yield block.
val (tmpFile1, tmpFile2) = usingResouce.run.value tmpFile1 shouldNot exist tmpFile2 shouldNot exist
This ResourceT type is an opacity alias to F[Resource[F, A]]. All type classes and helper functions for this ResourceT type are defined in the companion object ResourceT
F[Resource[F, A]]
The data structure that provides automatic resource management.
ResourceT
can be used as a monad transformer for scalaz.NameGiven a resource that creates temporary files
when using temporary file created by
resouce
in afor
/yield
block, those temporary files should be available.and those files should have been deleted after the
for
/yield
block.val (tmpFile1, tmpFile2) = usingResouce.run.value tmpFile1 shouldNot exist tmpFile2 shouldNot exist
This
ResourceT
type is an opacity alias toF[Resource[F, A]]
. All type classes and helper functions for thisResourceT
type are defined in the companion object ResourceT