trait Context[F[_]] extends AnyRef
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.
- Source
- Context.scala
- Alphabetic
- By Inheritance
- Context
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Abstract Value Members
- abstract 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 transformationC => F ~> F
.If an effect
F
that depends on Local is not provided with an initial value, through eitherset
orsetK
, 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) }
- abstract def monad: Monad[F]
Concrete Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- 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. - final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()