trait WithRun[F[_], G[_], C] extends WithProvide[F, G, C] with WithLocal[F, C] with RunContext[F] with Unlift[G, F]
Synonym for both RunContext and Unlift with explicit C as Ctx and G as Lower for better type
inference
Can be seen as transformation F[_] = C => G[_]
- Alphabetic
- By Inheritance
- WithRun
- Unlift
- RunContext
- WithLocal
- WithContext
- Local
- Context
- WithProvide
- Lift
- Provide
- ContextBase
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
-
type
Ctx = C
- Definition Classes
- WithRun → WithContext → Context → WithProvide → Provide
-
type
Lower[A] = G[A]
Result effect type without any notion of context
Result effect type without any notion of context
- Definition Classes
- WithProvide → Provide
Abstract Value Members
-
abstract
def
context: F[Ctx]
- Definition Classes
- Context
-
abstract
def
functor: Functor[F]
- Definition Classes
- Context
- abstract def lift[A](fa: G[A]): F[A]
-
abstract
def
local[A](fa: F[A])(project: (WithRun.Ctx) ⇒ WithRun.Ctx): F[A]
Alters context for computation
Alters context for computation
- fa
computation that is going to run with different context
- project
pure function
- returns
result of ran computation
fa
- Definition Classes
- WithLocal → Local
Example of usage is to hide sensitive information
case class UserContext( id: String, phoneNumber: String //very sensitive ) def hidePartOfPhoneNumber: String => String = ??? def contextualLogInfo[F[_]](message: String)(implicit hasUserContext: UserContext In F): F[Unit] = ??? //logs both message AND UserContext def program[F[_]: Monad] = for { user <- obtainUserSomehow[F] implicit0(hasUserContext: In[User, F]) <- Context.const[F, User](user.toContext) logUser = contextualLogInfo[F](s"Successfully obtained user") _ <- logUser.local(hidePartOfPhoneNumber) //logs only part of phone number } yield ()
Example: -
abstract
def
runContext[A](fa: F[A])(ctx: WithRun.Ctx): Lower[A]
Runs
faprovidingctxto it.Runs
faprovidingctxto it.One can treat F as function of type
Ctx => Lower[A]so this method applies it toctx.- fa
Contextual computation
- returns
Result of running fa and providing it context
- Definition Classes
- WithProvide → Provide
Example of usage is to hide sensitive information across a part of service
import tofu.syntax.context._ case class UserContext( id: String, phoneNumber: String //very sensitive ) def hidePartOfPhoneNumber: String => String = ??? def contextualLogInfo[F[_]](message: String)(implicit hasUserContext: UserContext In F): F[Unit] = ??? //logs both message AND UserContext def program[F[_]: WithRun[*[_], G[_], UserContext], G[_]: Monad] = for { user <- obtainUserSomehow[G] logUser = contextualLogInfo[F](s"Successfully obtained user") _ <- runContext[F](logUser)(user.toContext) //G[Unit] } yield ()
Example:
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
-
def
andThen[H[_]](ugh: Unlift[F, H])(implicit arg0: Monad[H]): Unlift[G, H]
- Definition Classes
- Unlift
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
asWithContext: WithContext[F, C]
- Definition Classes
- WithContext → Context
-
def
ask[A](f: (WithRun.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)
- Definition Classes
- WithContext → Context
- Note
It does not affect context itself.
-
def
askF[A](f: (WithRun.Ctx) ⇒ F[A])(implicit F: FlatMap[F]): F[A]
Same as ask but
fis effectualSame as ask but
fis effectual- Definition Classes
- WithContext → Context
-
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[WithRun.Ctx, A]): ContextExtractInstance[F, WithRun.Ctx, 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
- Definition Classes
- WithContext → Context
-
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
-
def
liftF: FunctionK[G, F]
- Definition Classes
- Lift
-
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()
-
def
runContextK(ctx: WithRun.Ctx): ~>[F, Lower]
Same as runContext but higher-kinded.
Same as runContext but higher-kinded.
- Definition Classes
- WithProvide → Provide
trait ProcessHandler[G[_]] { def mapK[M[_]](fk: G ~> M): ProcessHandler[M] = ??? //...other methods } type WithMyContext[F[_], A] = ReaderT[F, MyCtx, A] val contextualProcessHandler: ProcessHandler[IO WithMyContext _] = ??? val processHandler: ProcessHandler[IO] = processHandler.mapK( WithProvide[IO WithMyContext _, IO, MyCtx].runContextK )
Example: -
def
runEquivalent[A](eq: Equivalent[Ctx, A]): WithRun[F, G, A]
Allows to focus Provide on inner parts of its context with equivalence lens.
Allows to focus Provide on inner parts of its context with equivalence lens.
- eq
lens that can convert from
Ctxvalue of typeA
- Definition Classes
- WithRun → RunContext
-
def
runExtract[A](extract: Extract[A, WithRun.Ctx]): WithProvide[F, Lower, A]
Allows to focus Provide on inner parts of its context with lens.
Allows to focus Provide on inner parts of its context with lens.
- extract
lens that can extract from
Ctxvalue of typeA
- Definition Classes
- WithProvide → Provide
-
def
self: WithRun[F, G, C]
- Definition Classes
- WithRun → RunContext → WithProvide → Provide
-
def
subIso(implicit G: Functor[F]): F[IsoK[G, F]]
- Definition Classes
- Unlift
-
def
subcontext[A](contains: Contains[WithRun.Ctx, A]): WithLocal[F, A]
Allows to focus Local on inner parts of its context with lens.
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
def
unlift: F[~>[F, G]]
Allows to convert some context-unaware computation into contextual one.
Allows to convert some context-unaware computation into contextual one.
- Definition Classes
- WithRun → Unlift → RunContext
trait ProcessHandler[G[_]] { def mapK[M[_]](fk: G ~> M): ProcessHandler[M] = ??? //...other methods } type WithMyContext[F[_], A] = ReaderT[F, MyCtx, A] val processHandler: ProcessHandler[IO WithMyContext _] = ??? val contextualHandler: IO WithMyContext ProcessHandler[IO] = processHandler.mapK( WithRun[WithMyContext[IO, _], IO, MyCtx].unlift.map(fk => processHandler.mapK(fk)) ) //now it is able to process MyCtx but is wrapped in IO WithMyContext *
Example: -
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