Packages

p

cats

effect

package effect

Ordering
  1. Alphabetic
Visibility
  1. Public
  2. All

Type Members

  1. trait Async[F[_]] extends Sync[F] with LiftIO[F] with Serializable

    A monad that can describe asynchronous or synchronous computations that produce exactly one result.

    A monad that can describe asynchronous or synchronous computations that produce exactly one result.

    Annotations
    @implicitNotFound( ... )
  2. trait Effect[F[_]] extends Async[F] with Serializable

    A monad that can suspend side effects into the F context and that supports lazy and potentially asynchronous evaluation.

    A monad that can suspend side effects into the F context and that supports lazy and potentially asynchronous evaluation.

    Annotations
    @implicitNotFound( ... )
  3. trait Fiber[F[+_], +A] extends AnyRef

    Fiber represents the (pure) result of an Async data type (e.g.

    Fiber represents the (pure) result of an Async data type (e.g. IO) being started concurrently and that can be either joined or cancelled.

    You can think of fibers as being lightweight threads, a fiber being a concurrency primitive for doing cooperative multi-tasking.

    For example a Fiber value is the result of evaluating IO.start:

    val io = IO.shift *> IO(println("Hello!"))
    
    val fiber: IO[Fiber[IO, Unit]] = io.start

    Usage example:

    for {
      fiber <- IO.shift *> launchMissiles.start
      _ <- runToBunker.handleErrorWith { error =>
        // Retreat failed, cancel launch (maybe we should
        // have retreated to our bunker before the launch?)
        fiber.cancel *> IO.raiseError(error)
      }
      aftermath <- fiber.join
    } yield {
      aftermath
    }
  4. sealed abstract class IO[+A] extends AnyRef

    A pure abstraction representing the intention to perform a side effect, where the result of that side effect may be obtained synchronously (via return) or asynchronously (via callback).

    A pure abstraction representing the intention to perform a side effect, where the result of that side effect may be obtained synchronously (via return) or asynchronously (via callback).

    Effects contained within this abstraction are not evaluated until the "end of the world", which is to say, when one of the "unsafe" methods are used. Effectful results are not memoized, meaning that memory overhead is minimal (and no leaks), and also that a single effect may be run multiple times in a referentially-transparent manner. For example:

    val ioa = IO { println("hey!") }
    
    val program = for {
      _ <- ioa
      _ <- ioa
    } yield ()
    
    program.unsafeRunSync()

    The above will print "hey!" twice, as the effect will be re-run each time it is sequenced in the monadic chain.

    IO is trampolined for all synchronous joins. This means that you can safely call flatMap in a recursive function of arbitrary depth, without fear of blowing the stack. However, IO cannot guarantee stack-safety in the presence of arbitrarily nested asynchronous suspensions. This is quite simply because it is impossible (on the JVM) to guarantee stack-safety in that case. For example:

    def lie[A]: IO[A] = IO.async(cb => cb(Right(lie))).flatMap(a => a)

    This should blow the stack when evaluated. Also note that there is no way to encode this using tailRecM in such a way that it does not blow the stack. Thus, the tailRecM on Monad[IO] is not guaranteed to produce an IO which is stack-safe when run, but will rather make every attempt to do so barring pathological structure.

    IO makes no attempt to control finalization or guaranteed resource-safety in the presence of concurrent preemption, simply because IO does not care about concurrent preemption at all! IO actions are not interruptible and should be considered broadly-speaking atomic, at least when used purely.

  5. trait LiftIO[F[_]] extends Serializable
    Annotations
    @implicitNotFound( ... )
  6. trait Sync[F[_]] extends MonadError[F, Throwable] with Serializable

    A monad that can suspend the execution of side effects in the F[_] context.

  7. trait Timer[F[_]] extends AnyRef

    Timer is a scheduler of tasks.

    Timer is a scheduler of tasks.

    This is the purely functional equivalent of:

    It provides:

    1. the ability to get the current time
    2. thread / call-stack shifting
    3. ability to delay the execution of a task with a specified time duration

    It does all of that in an F monadic context that can suspend side effects and is capable of asynchronous execution (e.g. IO).

    This is NOT a type-class, as it does not have the coherence requirement.

    Annotations
    @implicitNotFound( ... )

Value Members

  1. object Async extends AsyncInstances with Serializable
  2. object Effect extends EffectInstances with Serializable
  3. object IO extends IOInstances

  4. object LiftIO extends LiftIOInstances with Serializable
  5. object Sync extends SyncInstances with Serializable
  6. object Timer

Ungrouped