FS2Provide

tofu.fs2Instances.FS2Provide
trait FS2Provide[F[_], G[_], R] extends WithProvide[[_] =>> Stream[F, _$55], [_] =>> Stream[G, _$56], R]

Attributes

Graph
Supertypes
trait WithProvide[[_] =>> Stream[F, _$55], [_] =>> Stream[G, _$56], R]
trait Lift[[_] =>> Stream[G, _$56], [_] =>> Stream[F, _$55]]
trait Provide[[_] =>> Stream[F, _$55]]
trait ContextBase
class Object
trait Matchable
class Any
Show all
Known subtypes
trait FS2RunContext[F, G, R]

Members list

Type members

Inherited types

override type Ctx = R

Attributes

Inherited from:
WithProvide
override type Lower[A] = [_] =>> Stream[G, _$56][A]

Result effect type without any notion of context

Result effect type without any notion of context

Attributes

Inherited from:
WithProvide

Value members

Concrete methods

def lift[A](fa: Stream[G, A]): Stream[F, A]

Converts context-unaware computation into contextual one by ignoring context

Converts context-unaware computation into contextual one by ignoring context

One can treat F[A] as function of type Ctx => Lower[A] so this method creates something like _ => la which has type Ctx => Lower[A]

Attributes

def runContext[A](fa: Stream[F, A])(ctx: R): Stream[G, A]

Runs fa providing ctx to it.

Runs fa providing ctx to it.

One can treat F as function of type Ctx => Lower[A] so this method applies it to ctx.

Value parameters

fa

Contextual computation

Attributes

Returns

Result of running fa and providing it context

Example

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
() 

Inherited methods

def liftF: FunctionK[[_] =>> Stream[G, _$56], [_] =>> Stream[F, _$55]]

Attributes

Inherited from:
Lift
override def runContextK(ctx: Ctx): FunctionK[[_] =>> Stream[F, _$55], Lower]

Same as runContext but higher-kinded.

Same as runContext but higher-kinded.

Attributes

Example
 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 ) 
Definition Classes
WithProvide -> Provide
Inherited from:
WithProvide
override def runExtract[A](extract: Extract[A, Ctx]): WithProvide[[_] =>> Stream[F, _$55], 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.

Value parameters

extract

lens that can extract from Ctx value of type A

Attributes

Definition Classes
WithProvide -> Provide
Inherited from:
WithProvide
def self: WithProvide[[_] =>> Stream[F, _$55], Lower, Ctx]

Attributes

Inherited from:
WithProvide

Implicits

Implicits

implicit def WP: WithProvide[F, G, R]