|Maintainer||Edward Kmett <email@example.com>|
The environment comonad holds a value along with some retrievable context.
This module specifies the environment comonad transformer (aka coreader), which is left adjoint to the reader comonad.
The following sets up an experiment that retains its initial value in the background:
let initial = env 0 0
Extract simply retrieves the value:
Play around with the value, in our case producing a negative value:
let experiment = fmap (+ 10) initial
Oh noes, something went wrong, 10 isn't very negative! Better restore the initial value using the default:
let initialRestored = experiment =>> ask
The strict environment comonad
The strict environment comonad transformer
|EnvT e (w a)|
|ComonadTrans (EnvT e)|
|ComonadHoist (EnvT e)|
|Functor w => Functor (EnvT e w)|
|(Typeable s, Typeable1 w) => Typeable1 (EnvT s w)|
|Foldable w => Foldable (EnvT e w)|
|Traversable w => Traversable (EnvT e w)|
|Comonad w => Comonad (EnvT e w)|
|(Semigroup e, ComonadApply w) => ComonadApply (EnvT e w)|
|(Semigroup e, Apply w) => Apply (EnvT e w)|
|Extend w => Extend (EnvT e w)|
|(Data e, Typeable1 w, Data (w a), Data a) => Data (EnvT e w a)|
|(Typeable s, Typeable1 w, Typeable a) => Typeable (EnvT s w a)|
Gets rid of the environment. This differs from
extract in that it will
not continue extracting the value from the contained comonad.
ask, but modifies the resulting value with a function.
asks = f . ask