trait Context[F[_]] extends ContextBase
Declares that F can provide value of type Ctx
In other words this trait tells you that F is some kind of Reader or function of type Ctx => F[A]. The best way to
use it is through WithContext or In
This can be seen as global value for your Application or for a part of it.
- Self Type
- Context[F]
- Annotations
- @deprecated
- Deprecated
(Since version 0.10.3) Migrate to With* typeclasses
One common use of this is to make contextual logging:
import tofu.syntax.console._ def contexualConsolling[F[_]: Console: FlatMap](message: String)(implicit hasMyCtx: F HasContext MyCtx): F[Unit] = hasMyCtx.askF(ctx => puts"$message (Also context: $ctx)")
so when you have
MyCtx(3)the call ofcontextualConsolling("Hi!")printsHi! (Also MyCtx(3))
- Alphabetic
- By Inheritance
- Context
- ContextBase
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
- abstract type Ctx
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
ask[A](f: (Ctx) ⇒ A): F[A]
Returns context modified by pure function
f.Returns context modified by pure function
f.For example one can use it like that:
Context[F].ask(myCtx => myCtx.toString)Also there is more convenient syntax:
import tofu.syntax.context._ ask[F](myCtx => myCtx.toString)
- Note
It does not affect context itself.
-
def
askF[A](f: (Ctx) ⇒ F[A])(implicit F: FlatMap[F]): F[A]
Same as ask but
fis effectual -
def
clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native() @IntrinsicCandidate()
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
extract[A](extract: Extract[Ctx, A]): WithContext[F, A]
Allows to focus context on its inside with lens.
Allows to focus context on its inside with lens.
- extract
lens that can extract value of type
AfromCtx
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @IntrinsicCandidate()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @IntrinsicCandidate()
-
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() @IntrinsicCandidate()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @IntrinsicCandidate()
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
Deprecated Value Members
-
def
finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] ) @Deprecated
- Deprecated