cats.effect

package cats.effect

Type members

Classlikes

sealed abstract case class ExitCode

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.

Companion
object
object ExitCode
Companion
class
sealed abstract class IO[+A] extends IOPlatform[A]

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).

IO values are pure, immutable values and thus preserve referential transparency, being usable in functional programming. An IO is a data structure that represents just a description of a side effectful computation.

IO can describe synchronous or asynchronous computations that:

  1. on evaluation yield exactly one result
  2. can end in either success or failure and in case of failure flatMap chains get short-circuited (IO implementing the algebra of MonadError)
  3. can be canceled, but note this capability relies on the user to provide cancelation logic

Effects described via 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 in its flatMap evaluation. This means that you can safely call flatMap in a recursive function of arbitrary depth, without fear of blowing the stack.

def fib(n: Int, a: Long = 0, b: Long = 1): IO[Long] =
 IO.pure(a + b) flatMap { b2 =>
   if (n > 0)
     fib(n - 1, b, b2)
   else
     IO.pure(a)
 }
Companion
object
object IO extends IOCompanionPlatform with IOLowPriorityImplicits
Companion
class
trait IOApp
Companion
object
object IOApp
Companion
class
sealed trait IOLocal[A]
Companion
object
object IOLocal
Companion
class
trait LiftIO[F[_]]
Companion
object
object LiftIO
Companion
class
sealed abstract class SyncIO[+A]

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.

Companion
object
object SyncIO extends SyncIOCompanionPlatform with SyncIOLowPriorityImplicits
Companion
class
object implicits extends AllSyntax with AllInstances

Types

type Async[F[_]] = Async[F]
type Clock[F[_]] = Clock[F]
type Concurrent[F[_]] = Concurrent[F]
type Cont[F[_], K, R] = Cont[F, K, R]
type Deferred[F[_], A] = Deferred[F, A]
type Fiber[F[_], E, A] = Fiber[F, E, A]
type FiberIO[A] = Fiber[[A] =>> IO[A], Throwable, A]
type GenConcurrent[F[_], E] = GenConcurrent[F, E]
type GenSpawn[F[_], E] = GenSpawn[F, E]
type GenTemporal[F[_], E] = GenTemporal[F, E]
type MonadCancel[F[_], E] = MonadCancel[F, E]
type MonadCancelThrow[F[_]] = MonadCancelThrow[F]
type Outcome[F[_], E, A] = Outcome[F, E, A]
type OutcomeIO[A] = Outcome[[A] =>> IO[A], Throwable, A]
type ParallelF[F[_], A] = T[F, A]
type Poll[F[_]] = Poll[F]
type Ref[F[_], A] = Ref[F, A]
type Resource[F[_], +A] = Resource[F, A]
type ResourceIO[A] = Resource[[A] =>> IO[A], A]
type Spawn[F[_]] = Spawn[F]
type Sync[F[_]] = Sync[F]
type Temporal[F[_]] = Temporal[F]
type Unique[F[_]] = Unique[F]

Value members

Concrete fields

val Async: Async
val Clock: Clock
val Concurrent: GenConcurrent
val Deferred: Deferred
val GenConcurrent: GenConcurrent
val GenSpawn: GenSpawn
val GenTemporal: GenTemporal
val MonadCancel: MonadCancel
val MonadCancelThrow: MonadCancel
val Outcome: Outcome
val ParallelF: ParallelF
val Ref: Ref
val Resource: Resource
val Spawn: GenSpawn
val Sync: Sync
val Temporal: GenTemporal
val Unique: Unique