Type Classes

The following graphic represents the current hierarchy of Cats Effect:

cats-effect typeclasses

MonadError belongs in the Cats project whereas the rest of the typeclasses belong in Cats Effect. On the side menu, you’ll find more information about each of them, including examples.

Cheat sheet

typeclasses cheat sheet


Can safely acquire and release resources

def bracket[A, B](acquire: F[A])(use: A => F[B])
    (release: A => F[Unit]): F[B]


Can convert any given IO[A] into F[A]. Useful for defining parametric signatures and composing monad transformer stacks

def liftIO[A](ioa: IO[A]): F[A]


Can suspend(describe) synchronous side-effecting code in F. But can’t evaluate(run) it

def delay[A](thunk: => A): F[A]


Can suspend synchronous/asynchronous side-effecting code in F. Can describe computations, that may be executed independent of the main program flow (on another thread or machine)

def async[A](k: (Either[Throwable, A] => Unit) => Unit): F[A]


Can concurrently start or cancel the side-effecting code in F

def start[A](fa: F[A]): F[Fiber[F, A]]
def race[A, B](fa: F[A], fb: F[B]): F[Either[A, B]]
def cancelable[A](k: (Either[Throwable, A] => Unit) => CancelToken[F]): F[A]
trait Fiber[F[_], A] {
  def cancel: F[Unit]
  def join: F[A]


Allows lazy and potentially asynchronous evaluation of side-effecting code in F

def runAsync[A](fa: F[A])(cb: Either[Throwable, A] => IO[Unit]): SyncIO[Unit]


Allows cancelable and concurrent evaluation of side-effecting code in F

def runCancelable[A](fa: F[A])(cb: Either[Throwable, A] => IO[Unit]): SyncIO[CancelToken[F]]