effectful-core-2.3.0.1: An easy to use, performant extensible effects library.
Safe HaskellSafe-Inferred
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 :: Effect where Source #

Constructors

Ask :: Reader r m r 
Local :: (r -> r) -> m a -> Reader r m a 

Instances

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

Defined in Effectful.Reader.Dynamic

Handlers

runReader Source #

Arguments

:: 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

:: (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 :: (HasCallStack, Reader r :> es) => Eff es r Source #

Fetch the value of the environment.

asks Source #

Arguments

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

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