Object

com.thoughtworks.zerocost

resourcet

Related Doc: package zerocost

Permalink

object resourcet extends ResourceTInstances0

The namespace that contains the covariant ResourceT.

Usage:

import com.thoughtworks.zerocost.resourcet._
Source
resourcet.scala
Linear Supertypes
ResourceTInstances0, ResourceTInstances1, ResourceTInstances2, ResourceTInstances3, AnyRef, Any
Ordering
  1. Grouped
  2. Alphabetic
  3. By Inheritance
Inherited
  1. resourcet
  2. ResourceTInstances0
  3. ResourceTInstances1
  4. ResourceTInstances2
  5. ResourceTInstances3
  6. AnyRef
  7. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. trait MonadicCloseable[F[+_]] extends Any

    Permalink

    An object that may hold resources until it is closed.

    An object that may hold resources until it is closed.

    Similar to java.lang.AutoCloseable except the close operation is monadic.

  2. final case class Resource[F[+_], +A](value: A, release: F[Unit]) extends Product with Serializable

    Permalink

    A container of a value and a function to release the value.

    A container of a value and a function to release the value.

    F

    the monadic type of release

    A

    the type of value

    release

    Releases value and all resource dependencies during creating value.

    Note

    After release, value should not be used if:

    ,

    This Resource will become a case class. Use Resource.apply instead of new Serializable with Resource[F, A] { ... }.

  3. type ResourceT[F[+_], +A] = resourcet.OpacityTypes.ResourceT[F, A]

    Permalink

    The data structure that provides automatic resource management.

    The data structure that provides automatic resource management.

    Example:
    1. ResourceT can be used as a monad transformer for scala.Function0

      import scala.Function0
      import cats.instances.function._
      import com.thoughtworks.zerocost.resourcet._
      type RAII[A] = ResourceT[Function0, A]

      Given a resource that creates temporary files

      trait MyResource extends AutoCloseable {
        def inUse(): Unit
      }
      val myResourceStub0 = stub[MyResource]
      val myResourceStub1 = stub[MyResource]
      val myResourceFactoryMock = mockFunction[MyResource]
      myResourceFactoryMock.expects().returns(myResourceStub0)
      myResourceFactoryMock.expects().returns(myResourceStub1)
      val resource: RAII[MyResource] = ResourceT.autoCloseable[Function0, MyResource](myResourceFactoryMock)

      when using temporary file created by resouce in a for / yield block, those temporary files should be available.

      import cats.syntax.all._
      val usingResouce = for {
        tmpFile0 <- resource
        tmpFile1 <- resource
      } yield {
        tmpFile0 should be(myResourceStub0)
        tmpFile1 should be(myResourceStub1)
        tmpFile1.inUse()
      }

      and those files should have been deleted after the for / yield block.

      usingResouce.run.apply()
      ((myResourceStub0.inUse _): () => Unit).verify().never()
      ((myResourceStub0.close _): () => Unit).verify().once()
      ((myResourceStub1.inUse _): () => Unit).verify().once()
      ((myResourceStub1.close _): () => Unit).verify().once()
    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

  4. implicit final class ResourceTOps[F[+_], A] extends AnyRef

    Permalink
  5. type Releasable[F[+_], +A] = Resource[F, A]

    Permalink
    Annotations
    @deprecated
    Deprecated

    (Since version 3.0.0) Use Resource instead.

Value Members

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

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

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

    Permalink
    Definition Classes
    AnyRef → Any
  4. object Resource extends Serializable

    Permalink
  5. object ResourceT

    Permalink

    The companion object of ResourceT that contains converters and type classes.

    The companion object of ResourceT that contains converters and type classes.

    Note

    There are some implicit method that provides cats.Monads as monad transformers of F. Those monads running will collect all resources, which will be open and release altogether when ResourceTOps.run is called.

  6. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  7. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  8. final def eq(arg0: AnyRef): Boolean

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

    Permalink
    Definition Classes
    AnyRef → Any
  10. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  11. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  12. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  13. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  14. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  15. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  16. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  17. val opacityTypes: OpacityTypes

    Permalink

    The type-level Pimpl in order to prevent the Scala compiler seeing the actual type of ResourceT

    The type-level Pimpl in order to prevent the Scala compiler seeing the actual type of ResourceT

    Note

    For internal usage only.

  18. implicit def resourceTApplicative[F[+_]](implicit arg0: Applicative[F]): Applicative[[β$0$]resourcet.OpacityTypes.ResourceT[F, β$0$]]

    Permalink

    Definition Classes
    ResourceTInstances3
  19. implicit def resourceTLiftIO[F[+_]](implicit arg0: LiftIO[F]): LiftIO[[β$10$]resourcet.OpacityTypes.ResourceT[F, β$10$]] with LiftIO[[β$11$]resourcet.OpacityTypes.ResourceT[F, β$11$]]

    Permalink

    Definition Classes
    ResourceTInstances0
  20. implicit def resourceTMonad[F[+_]](implicit arg0: Monad[F]): Monad[[β$1$]resourcet.OpacityTypes.ResourceT[F, β$1$]]

    Permalink

    Definition Classes
    ResourceTInstances2
  21. implicit def resourceTParallelApply[F[+_]](implicit F0: Apply[[β$18$]Parallel[F, β$18$]]): Apply[[β$20$]Parallel[[+β$19$]resourcet.OpacityTypes.ResourceT[F, β$19$], β$20$]]

    Permalink

  22. implicit def resourceTParallelLiftIO[F[+_]](implicit F0: LiftIO[[β$2$]Parallel[F, β$2$]]): LiftIO[[β$4$]Parallel[[+β$3$]resourcet.OpacityTypes.ResourceT[F, β$3$], β$4$]]

    Permalink

    Definition Classes
    ResourceTInstances1
  23. implicit def resourceTParallelMonad[F[+_]](implicit F0: Monad[[β$6$]Parallel[F, β$6$]]): Monad[[β$8$]Parallel[[+β$7$]resourcet.OpacityTypes.ResourceT[F, β$7$], β$8$]]

    Permalink

    Definition Classes
    ResourceTInstances0
  24. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  25. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  26. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  27. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  28. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from ResourceTInstances0

Inherited from ResourceTInstances1

Inherited from ResourceTInstances2

Inherited from ResourceTInstances3

Inherited from AnyRef

Inherited from Any

Type classes

Ungrouped