Packages

p

cats

effect

package effect

Source
package.scala
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. sealed abstract case class ExitCode extends Product with Serializable

    Represents the exit code of an application.

    Represents the exit code of an application.

    code is constrained to a range from 0 to 255, inclusive.

  7. type Fiber[F[_], E, A] = effect.kernel.Fiber[F, E, A]
  8. type FiberIO[A] = effect.kernel.Fiber[IO, Throwable, A]
  9. sealed abstract class IO[+A] extends IOPlatform[A]
  10. trait IOApp extends AnyRef
  11. trait LiftIO[F[_]] extends AnyRef
  12. type MonadCancel[F[_], E] = effect.kernel.MonadCancel[F, E]
  13. type MonadCancelThrow[F[_]] = effect.kernel.MonadCancel[F, Throwable]
  14. type Outcome[F[_], E, A] = effect.kernel.Outcome[F, E, A]
  15. type OutcomeIO[A] = effect.kernel.Outcome[IO, Throwable, A]
  16. type ParallelF[F[_], A] = T[F, A]
  17. type Poll[F[_]] = effect.kernel.Poll[F]
  18. 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

  19. type Sync[F[_]] = effect.kernel.Sync[F]
  20. type SyncEffect[F[_]] = effect.kernel.SyncEffect[F]
  21. 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.

  22. type Temporal[F[_], E] = effect.kernel.Temporal[F, E]
  23. type TemporalThrow[F[_]] = effect.kernel.Temporal[F, Throwable]
  24. 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 MonadCancel: effect.kernel.MonadCancel.type
  6. val Outcome: effect.kernel.Outcome.type
  7. val ParallelF: effect.kernel.Par.ParallelF.type
  8. val Sync: effect.kernel.Sync.type
  9. val SyncEffect: effect.kernel.SyncEffect.type
  10. val Temporal: effect.kernel.Temporal.type
  11. object ExitCode extends Serializable
  12. object IO extends IOCompanionPlatform with IOLowPriorityImplicits
  13. object IOApp
  14. object LiftIO
  15. object Resource extends ResourceInstances with ResourcePlatform
  16. object SyncIO extends SyncIOLowPriorityImplicits
  17. object UnsafeTimer

Inherited from AnyRef

Inherited from Any

Ungrouped