haskus-utils-1.5: Haskus utility modules

Safe HaskellNone
LanguageHaskell2010

Haskus.Utils.MonadVar

Contents

Description

Monadic variable with cache

Synopsis

Documentation

data MonadVar m s a Source #

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

Constructors

MonadVar !(m s) (s -> a)

IO accessor + modifier function

CachedMonadVar a !s !(m s) (s -> a)

Additional cached transformed and read values.

Instances
Functor (MonadVar m s) Source # 
Instance details

Defined in Haskus.Utils.MonadVar

Methods

fmap :: (a -> b) -> MonadVar m s a -> MonadVar m s b #

(<$) :: a -> MonadVar m s b -> MonadVar m s a #

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 #

Constructors

MonadVarNE a !(Maybe s) !(m s) (s -> a)

Additional cached transformed and read values.

Instances
Functor (MonadVarNE m s) Source # 
Instance details

Defined in Haskus.Utils.MonadVar

Methods

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