Safe Haskell | None |
---|---|
Language | Haskell2010 |
Monadic variable with cache
Synopsis
- data MonadVar m s a
- = MonadVar !(m s) (s -> a)
- | CachedMonadVar a !s !(m s) (s -> a)
- updateMonadVarForce :: (Monad m, Eq s) => MonadVar m s a -> m (MonadVar m s a)
- updateMonadVarMaybe :: (Monad m, Eq s) => MonadVar m s a -> m (Maybe (MonadVar m s a))
- updateMonadVar :: (Monad m, Eq s) => MonadVar m s a -> m (MonadVar m s a)
- data MonadVarNE m s a = MonadVarNE a !(Maybe s) !(m s) (s -> a)
- updateMonadVarNEMaybe :: (Monad m, Eq s) => MonadVarNE m s a -> m (Maybe (MonadVarNE m s a))
- updateMonadVarNE :: (Monad m, Eq s) => MonadVarNE m s a -> m (MonadVarNE m s a)
Documentation
A value that can be read with IO. The last read can be cached in it too.
We store both the read value (type s) and a pure modifier function (s -> a). By doing this we can easily compare a read value to the cached one without performing extra computations. The functor instance compose with the modifier function.
The supposedly costly modifier function is applied lazily
MonadVar !(m s) (s -> a) | IO accessor + modifier function |
CachedMonadVar a !s !(m s) (s -> a) | Additional cached transformed and read values. |
updateMonadVarForce :: (Monad m, Eq s) => MonadVar m s a -> m (MonadVar m s a) Source #
Update an MonadVar without comparing to the cache even if it is available.
Invariably produce an MonadVar with cached values.
updateMonadVarMaybe :: (Monad m, Eq s) => MonadVar m s a -> m (Maybe (MonadVar m s a)) Source #
Check if the MonadVar cache needs to be updated.
Invariably produce an MonadVar with cached values or Nothing if the old one hasn't changed.
updateMonadVar :: (Monad m, Eq s) => MonadVar m s a -> m (MonadVar m s a) Source #
Check if the MonadVar cache needs to be updated. Return the updated MonadVar.
Invariably produce an MonadVar with cached values.
Non-empty
data MonadVarNE m s a Source #
MonadVarNE a !(Maybe s) !(m s) (s -> a) | Additional cached transformed and read values. |
Instances
Functor (MonadVarNE m s) Source # | |
Defined in Haskus.Utils.MonadVar fmap :: (a -> b) -> MonadVarNE m s a -> MonadVarNE m s b # (<$) :: a -> MonadVarNE m s b -> MonadVarNE m s a # |
updateMonadVarNEMaybe :: (Monad m, Eq s) => MonadVarNE m s a -> m (Maybe (MonadVarNE m s a)) Source #
Check if the MonadVarNE cache needs to be updated.
updateMonadVarNE :: (Monad m, Eq s) => MonadVarNE m s a -> m (MonadVarNE m s a) Source #
Check if the MonadVarNE cache needs to be updated. Return the updated MonadVarNE