Context

catcheffect.Context
See theContext companion object
trait Context[F[_]]

An abstraction that can construct an instance of the Local mtl algebra without any constraints.

You gain the (cap)ability to introduce a new instance of Local for any type, anywhere a Context is present.

For programs written in cats.data.Kleisli or tagless final, Context provides the ability to introduce new Local instances without having to lift any algebras or penalize your performance.

Nested use of Context is well defined.

Attributes

Companion
object
Source
Context.scala
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Abstract methods

def allocated[C](implicit sp: SourcePos): F[Local[F, C]]

The low-level primitive which makes up a Context.

The low-level primitive which makes up a Context. This api is low-level and potentially unsafe, so use it with caution.

allocated is more powerful than use in that you can write a program with Local without having an initial value yet. Allocated let's the user choose when to provide the initial value in either through set or a natural transformation C => F ~> F.

If an effect F that depends on Local is not provided with an initial value, through either set or setK, a detailed runtime error will be raised.

For instance, here is a good use-case for allocated.

trait MyAlgebra[F[_]] {
  def doThing: F[Unit]

  def mapK[G[_]](fk: F ~> G): MyAlgebra[G]
}
// Let it be an expensive operation to construct an instance of MyAlgebra,
// such that we only wish to construct it once.
def make[F[_]](loc: Local[F, Auth]): MyAlgebra[F] = ???

def processInput[F[_]](alg: MyAlgebra[F]) = ???
// ...
Context[F].allocated.flatMap{ loc =>
   val alg = make[F](loc)

   def runAuthedRequest(auth: Auth) =
     processInput[F](alg.mapK(loc.setK(auth)))

   startAuthedServer(runAuthedRequest)
}

Attributes

Source
Context.scala
def monad: Monad[F]

Attributes

Source
Context.scala

Concrete methods

def use[C, A](c: C)(f: Local[F, C] => F[A])(implicit sp: SourcePos): F[A]

Within the scope of f, the use of Local is well defined.

Within the scope of f, the use of Local is well defined.

If you use this combinator like you would a cats.effect.Resource's use, your program will be safe.

Attributes

Source
Context.scala