Type/Object

com.thoughtworks.raii.covariant

ResourceT

Related Docs: object ResourceT | package covariant

Permalink

type ResourceT[F[+_], +A] = covariant.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.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.

    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[Resource[F, A]]. All type classes and helper functions for this ResourceT type are defined in the companion object ResourceT

Visibility
  1. Public
  2. All

Abstract Value Members

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

    Permalink
    Definition Classes
    Any

Concrete Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    Any
  4. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  5. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    Any
  6. def hashCode(): Int

    Permalink
    Definition Classes
    Any
  7. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  8. def toString(): String

    Permalink
    Definition Classes
    Any

Ungrouped