Packages

p

cats

effect

package effect

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. effect
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. type Async[F[_]] = effect.kernel.Async[F]
  2. type Clock[F[_]] = effect.kernel.Clock[F]
  3. type Concurrent[F[_], E] = effect.kernel.Concurrent[F, E]
  4. type ConcurrentThrow[F[_]] = effect.kernel.Concurrent[F, Throwable]
  5. type Effect[F[_]] = effect.kernel.Effect[F]
  6. type Fiber[F[_], E, A] = effect.kernel.Fiber[F, E, A]
  7. type FiberIO[A] = effect.kernel.Fiber[IO, Throwable, A]
  8. sealed abstract class IO[+A] extends IOPlatform[A]
  9. trait IOApp extends AnyRef
  10. trait LiftIO[F[_]] extends AnyRef
  11. type Outcome[F[_], E, A] = effect.kernel.Outcome[F, E, A]
  12. type OutcomeIO[A] = effect.kernel.Outcome[IO, Throwable, A]
  13. type ParallelF[F[_], A] = T[F, A]
  14. type Poll[F[_]] = effect.kernel.Poll[F]
  15. sealed abstract class Resource[+F[_], +A] extends AnyRef

    The Resource is a data structure that captures the effectful allocation of a resource, along with its finalizer.

    The Resource is a data structure that captures the effectful allocation of a resource, along with its finalizer.

    This can be used to wrap expensive resources. Example:

    def open(file: File): Resource[IO, BufferedReader] =
      Resource(IO {
        val in = new BufferedReader(new FileReader(file))
        (in, IO(in.close()))
      })

    Usage is done via use and note that resource usage nests, because its implementation is specified in terms of Bracket:

    open(file1).use { in1 =>
      open(file2).use { in2 =>
        readFiles(in1, in2)
      }
    }

    Resource forms a MonadError on the resource type when the effect type has a cats.MonadError instance. Nested resources are released in reverse order of acquisition. Outer resources are released even if an inner use or release fails.

    def mkResource(s: String) = {
      val acquire = IO(println(s"Acquiring $$s")) *> IO.pure(s)
      def release(s: String) = IO(println(s"Releasing $$s"))
      Resource.make(acquire)(release)
    }
    
    val r = for {
      outer <- mkResource("outer")
    
      inner <- mkResource("inner")
    } yield (outer, inner)
    
    r.use { case (a, b) =>
      IO(println(s"Using $$a and $$b"))
    }

    On evaluation the above prints:

    Acquiring outer
    Acquiring inner
    Using outer and inner
    Releasing inner
    Releasing outer

    A Resource is nothing more than a data structure, an ADT, described by the following node types and that can be interpreted if needed:

    Normally users don't need to care about these node types, unless conversions from Resource into something else is needed (e.g. conversion from Resource into a streaming data type).

    F

    the effect type in which the resource is allocated and released

    A

    the type of resource

  16. type Sync[F[_]] = effect.kernel.Sync[F]
  17. type SyncEffect[F[_]] = effect.kernel.SyncEffect[F]
  18. sealed abstract class SyncIO[+A] extends AnyRef

    A pure abstraction representing the intention to perform a side effect, where the result of that side effect is obtained synchronously.

    A pure abstraction representing the intention to perform a side effect, where the result of that side effect is obtained synchronously.

    SyncIO is similar to IO, but does not support asynchronous computations. Consequently, a SyncIO can be run synchronously to obtain a result via unsafeRunSync. This is unlike IO#unsafeRunSync, which cannot be safely called in general -- doing so on the JVM blocks the calling thread while the async part of the computation is run and doing so on Scala.js throws an exception upon encountering an async boundary.

  19. type Temporal[F[_], E] = effect.kernel.Temporal[F, E]
  20. type TemporalThrow[F[_]] = effect.kernel.Temporal[F, Throwable]
  21. trait UnsafeTimer extends AnyRef

Value Members

  1. val Async: effect.kernel.Async.type
  2. val Clock: effect.kernel.Clock.type
  3. val Concurrent: effect.kernel.Concurrent.type
  4. val Effect: effect.kernel.Effect.type
  5. val Outcome: effect.kernel.Outcome.type
  6. val ParallelF: effect.kernel.Par.ParallelF.type
  7. val Sync: effect.kernel.Sync.type
  8. val SyncEffect: effect.kernel.SyncEffect.type
  9. val Temporal: effect.kernel.Temporal.type
  10. object IO extends IOCompanionPlatform with IOLowPriorityImplicits
  11. object LiftIO
  12. object Resource extends ResourceInstances with ResourcePlatform
  13. object SyncIO extends SyncIOLowPriorityImplicits
  14. object UnsafeTimer

Inherited from AnyRef

Inherited from Any

Ungrouped