reactive-banana-0.8.0.4: Library for functional reactive programming (FRP).

Safe HaskellNone
LanguageHaskell98

Reactive.Banana.Prim.Cached

Synopsis

Documentation

Utility for executing monadic actions once and then retrieving values from a cache.

Very useful for observable sharing.

class (Monad m, MonadFix m) => HasCache m where Source

Type class for monads that have a lazy Vault that can be used as a cache.

The cache has to be lazy in the values in order to be useful for recursion.

Methods

retrieve :: Key a -> m (Maybe a) Source

write :: Key a -> a -> m () Source

Instances

data Cached m a Source

runCached :: Cached m a -> m a Source

cache :: HasCache m => m a -> Cached m a Source

An action whose result will be cached. Executing the action the first time in the monad will execute the side effects. From then on, only the generated value will be returned.

fromPure :: HasCache m => a -> Cached m a Source

Return a pure value. Doesn't make use of the cache.

don'tCache :: HasCache m => m a -> Cached m a Source

Lift an action that is not chached, for instance because it is idempotent.

liftCached1 :: HasCache m => (a -> m b) -> Cached m a -> Cached m b Source

liftCached2 :: HasCache m => (a -> b -> m c) -> Cached m a -> Cached m b -> Cached m c Source