unliftio-0.2.21.0: The MonadUnliftIO typeclass for unlifting monads to IO (batteries included)
Safe HaskellNone
LanguageHaskell2010

UnliftIO.Memoize

Description

Memoize the results of actions. In other words: actions will be run once, on demand, and their results saved.

Exceptions semantics: if a synchronous exception is thrown while performing the computation, that result will be saved and rethrown each time runMemoized is called subsequently.'

Since: 0.2.8.0

Synopsis

Documentation

data Memoized a Source #

A "run once" value, with results saved. Extract the value with runMemoized. For single-threaded usage, you can use memoizeRef to create a value. If you need guarantees that only one thread will run the action at a time, use memoizeMVar.

Note that this type provides a Show instance for convenience, but not useful information can be provided.

Since: 0.2.8.0

Instances

Instances details
Monad Memoized Source # 
Instance details

Defined in UnliftIO.Memoize

Methods

(>>=) :: Memoized a -> (a -> Memoized b) -> Memoized b #

(>>) :: Memoized a -> Memoized b -> Memoized b #

return :: a -> Memoized a #

Functor Memoized Source # 
Instance details

Defined in UnliftIO.Memoize

Methods

fmap :: (a -> b) -> Memoized a -> Memoized b #

(<$) :: a -> Memoized b -> Memoized a #

Applicative Memoized Source # 
Instance details

Defined in UnliftIO.Memoize

Methods

pure :: a -> Memoized a #

(<*>) :: Memoized (a -> b) -> Memoized a -> Memoized b #

liftA2 :: (a -> b -> c) -> Memoized a -> Memoized b -> Memoized c #

(*>) :: Memoized a -> Memoized b -> Memoized b #

(<*) :: Memoized a -> Memoized b -> Memoized a #

Show (Memoized a) Source # 
Instance details

Defined in UnliftIO.Memoize

Methods

showsPrec :: Int -> Memoized a -> ShowS #

show :: Memoized a -> String #

showList :: [Memoized a] -> ShowS #

runMemoized :: MonadIO m => Memoized a -> m a Source #

Extract a value from a Memoized, running an action if no cached value is available.

Since: 0.2.8.0

memoizeRef :: MonadUnliftIO m => m a -> m (Memoized a) Source #

Create a new Memoized value using an IORef under the surface. Note that the action may be run in multiple threads simultaneously, so this may not be thread safe (depending on the underlying action). Consider using memoizeMVar.

Since: 0.2.8.0

memoizeMVar :: MonadUnliftIO m => m a -> m (Memoized a) Source #

Same as memoizeRef, but uses an MVar to ensure that an action is only run once, even in a multithreaded application.

Since: 0.2.8.0