trait Local[F[_]] extends Context[F]
Allows to run some computation with notion of altered context consider using WithLocal
for better type inference
- Self Type
- Local[F]
- Annotations
- @deprecated
- Deprecated
(Since version 0.10.3) Migrate to With* typeclasses
- Alphabetic
- By Inheritance
- Local
- Context
- ContextBase
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Abstract Value Members
- abstract def context: F[Ctx]
- Definition Classes
- Context
- abstract def functor: Functor[F]
- Definition Classes
- Context
- abstract def local[A](fa: F[A])(project: (Ctx) => 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
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:
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)
- Definition Classes
- Context
- Note
It does not affect context itself.
- def askF[A](f: (Ctx) => F[A])(implicit F: FlatMap[F]): F[A]
Same as ask but
f
is effectual - def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native() @IntrinsicCandidate()
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): 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
A
fromCtx
- Definition Classes
- Context
- final def getClass(): Class[_ <: AnyRef]
- 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()
- def subcontext[A](contains: Contains[Ctx, A]): WithLocal[F, A]
Allows to focus Local on inner parts of its context with lens.
Allows to focus Local on inner parts of its context with lens.
- contains
lens that can extract from
Ctx
or set some value of typeA
- 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(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
Deprecated Value Members
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable]) @Deprecated
- Deprecated