Packages

type ResourceT[F[_], A] = invariant.OpacityTypes.ResourceT[F, A]

The data structure that provides automatic resource management.

Source
covariant.scala
Example:
  1. ResourceT can be used as a monad transformer for scalaz.Name

    import scalaz.Name
    import com.thoughtworks.raii.invariant._
    type RAII[A] = ResourceT[Name, A]

    Given a resource that creates temporary files

    import java.io.File
    val resource: RAII[File] = ResourceT(Name(new Releasable[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.

    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
Note

This ResourceT type is an opacity alias to F[Releasable[F, A]]. All type classes and helper functions for this ResourceT type are defined in the companion object ResourceT

Ordering
  1. Alphabetic
Visibility
  1. Public
  2. All

Abstract Value Members

  1. abstract def getClass(): Class[_]
    Definition Classes
    Any

Concrete Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    Any
  2. final def ##(): Int
    Definition Classes
    Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. def equals(arg0: Any): Boolean
    Definition Classes
    Any
  6. def hashCode(): Int
    Definition Classes
    Any
  7. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  8. def toString(): String
    Definition Classes
    Any

Ungrouped