effectful-core-2.5.1.0: An easy to use, performant extensible effects library.
Safe HaskellNone
LanguageHaskell2010

Effectful.Reader.Dynamic

Description

The dynamically dispatched variant of the Reader effect.

Note: unless you plan to change interpretations at runtime, it's recommended to use the statically dispatched variant, i.e. Effectful.Reader.Static.

Synopsis

Effect

data Reader r (a :: Type -> Type) b where Source #

Constructors

Ask :: forall r (a :: Type -> Type). Reader r a r 
Local :: forall r (a :: Type -> Type) b. (r -> r) -> a b -> Reader r a b 

Instances

Instances details
type DispatchOf (Reader r) Source # 
Instance details

Defined in Effectful.Reader.Dynamic

Handlers

runReader Source #

Arguments

:: forall r (es :: [(Type -> Type) -> Type -> Type]) a. HasCallStack 
=> r

The initial environment.

-> Eff (Reader r ': es) a 
-> Eff es a 

Run the Reader effect with the given initial environment (via Effectful.Reader.Static).

withReader Source #

Arguments

:: forall r1 r2 (es :: [(Type -> Type) -> Type -> Type]) a. HasCallStack 
=> (r1 -> r2)

The function to modify the environment.

-> Eff (Reader r2 ': es) a

Computation to run in the modified environment.

-> Eff (Reader r1 ': es) a 

Execute a computation in a modified environment.

Since: 1.1.0.0

Operations

ask :: forall r (es :: [Effect]). (HasCallStack, Reader r :> es) => Eff es r Source #

Fetch the value of the environment.

asks Source #

Arguments

:: forall r (es :: [Effect]) a. (HasCallStack, Reader r :> es) 
=> (r -> a)

The function to apply to the environment.

-> Eff es a 

Retrieve a function of the current environment.

asks f ≡ f <$> ask

local Source #

Arguments

:: forall r (es :: [Effect]) a. (HasCallStack, Reader r :> es) 
=> (r -> r)

The function to modify the environment.

-> Eff es a 
-> Eff es a 

Execute a computation in a modified environment.

runReader r (local f m) ≡ runReader (f r) m