safe-buffer-monad-0.1.0: A monadic buffer resilient to exceptions

Safe HaskellNone
LanguageHaskell2010

SafeBuffer

Contents

Synopsis

SafeBufferMonad

class Monad m => SafeBufferMonad s m | m -> s where Source #

Minimal complete definition

readBuffer, writeBuffer, clearBuffer, modifyBuffer

Methods

readBuffer :: m s Source #

Retrieves the buffer's current content.

writeBuffer :: s -> m () Source #

Appends a message to the buffer.

clearBuffer :: m s Source #

Retrieves the buffer's current content before clearing it.

modifyBuffer :: (s -> s) -> m () Source #

Applies a given function to the buffer's content.

SafeBufferT

newtype SafeBufferT s m a Source #

Constructors

SafeBufferT 

Fields

Instances

MonadWriter r m => MonadWriter r (SafeBufferT s m) Source # 

Methods

writer :: (a, r) -> SafeBufferT s m a #

tell :: r -> SafeBufferT s m () #

listen :: SafeBufferT s m a -> SafeBufferT s m (a, r) #

pass :: SafeBufferT s m (a, r -> r) -> SafeBufferT s m a #

MonadState s m => MonadState s (SafeBufferT s m) Source # 

Methods

get :: SafeBufferT s m s #

put :: s -> SafeBufferT s m () #

state :: (s -> (a, s)) -> SafeBufferT s m a #

MonadError e m => MonadError e (SafeBufferT s m) Source # 

Methods

throwError :: e -> SafeBufferT s m a #

catchError :: SafeBufferT s m a -> (e -> SafeBufferT s m a) -> SafeBufferT s m a #

(MonadIO m, Monoid s) => SafeBufferMonad s (SafeBufferT s m) Source # 
MonadTrans (SafeBufferT s) Source # 

Methods

lift :: Monad m => m a -> SafeBufferT s m a #

Monad m => MonadReader (IORef s) (SafeBufferT s m) Source # 

Methods

ask :: SafeBufferT s m (IORef s) #

local :: (IORef s -> IORef s) -> SafeBufferT s m a -> SafeBufferT s m a #

reader :: (IORef s -> a) -> SafeBufferT s m a #

Monad m => Monad (SafeBufferT s m) Source # 

Methods

(>>=) :: SafeBufferT s m a -> (a -> SafeBufferT s m b) -> SafeBufferT s m b #

(>>) :: SafeBufferT s m a -> SafeBufferT s m b -> SafeBufferT s m b #

return :: a -> SafeBufferT s m a #

fail :: String -> SafeBufferT s m a #

Functor m => Functor (SafeBufferT s m) Source # 

Methods

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

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

MonadFix m => MonadFix (SafeBufferT s m) Source # 

Methods

mfix :: (a -> SafeBufferT s m a) -> SafeBufferT s m a #

MonadFail m => MonadFail (SafeBufferT s m) Source # 

Methods

fail :: String -> SafeBufferT s m a #

Applicative m => Applicative (SafeBufferT s m) Source # 

Methods

pure :: a -> SafeBufferT s m a #

(<*>) :: SafeBufferT s m (a -> b) -> SafeBufferT s m a -> SafeBufferT s m b #

liftA2 :: (a -> b -> c) -> SafeBufferT s m a -> SafeBufferT s m b -> SafeBufferT s m c #

(*>) :: SafeBufferT s m a -> SafeBufferT s m b -> SafeBufferT s m b #

(<*) :: SafeBufferT s m a -> SafeBufferT s m b -> SafeBufferT s m a #

MonadZip m => MonadZip (SafeBufferT s m) Source # 

Methods

mzip :: SafeBufferT s m a -> SafeBufferT s m b -> SafeBufferT s m (a, b) #

mzipWith :: (a -> b -> c) -> SafeBufferT s m a -> SafeBufferT s m b -> SafeBufferT s m c #

munzip :: SafeBufferT s m (a, b) -> (SafeBufferT s m a, SafeBufferT s m b) #

MonadIO m => MonadIO (SafeBufferT s m) Source # 

Methods

liftIO :: IO a -> SafeBufferT s m a #

Alternative m => Alternative (SafeBufferT s m) Source # 

Methods

empty :: SafeBufferT s m a #

(<|>) :: SafeBufferT s m a -> SafeBufferT s m a -> SafeBufferT s m a #

some :: SafeBufferT s m a -> SafeBufferT s m [a] #

many :: SafeBufferT s m a -> SafeBufferT s m [a] #

MonadPlus m => MonadPlus (SafeBufferT s m) Source # 

Methods

mzero :: SafeBufferT s m a #

mplus :: SafeBufferT s m a -> SafeBufferT s m a -> SafeBufferT s m a #

MonadThrow m => MonadThrow (SafeBufferT s m) Source # 

Methods

throwM :: Exception e => e -> SafeBufferT s m a #

MonadCatch m => MonadCatch (SafeBufferT s m) Source # 

Methods

catch :: Exception e => SafeBufferT s m a -> (e -> SafeBufferT s m a) -> SafeBufferT s m a #

MonadMask m => MonadMask (SafeBufferT s m) Source # 

Methods

mask :: ((forall a. SafeBufferT s m a -> SafeBufferT s m a) -> SafeBufferT s m b) -> SafeBufferT s m b #

uninterruptibleMask :: ((forall a. SafeBufferT s m a -> SafeBufferT s m a) -> SafeBufferT s m b) -> SafeBufferT s m b #

generalBracket :: SafeBufferT s m a -> (a -> ExitCase b -> SafeBufferT s m c) -> (a -> SafeBufferT s m b) -> SafeBufferT s m (b, c) #

MonadCont m => MonadCont (SafeBufferT s m) Source # 

Methods

callCC :: ((a -> SafeBufferT s m b) -> SafeBufferT s m a) -> SafeBufferT s m a #

runBuffer :: forall s m a b. (MonadIO m, MonadMask m, Monoid s) => (s -> m b) -> SafeBufferT s m a -> m a Source #

Runs a buffer and applies a given function to it. If any exception occurs while running the buffer, the function still runs before the exception is rethrown.

tryRunBuffer :: forall e s m a. (MonadIO m, MonadCatch m, Monoid s, Exception e) => SafeBufferT s m a -> m (s, Either e a) Source #

Runs a buffer and returns it, along with either an exception or the computation's result.

It purposefully does NOT catch async exceptions. To understand why, see Asynchronous exception handling in Haskell.

execBuffer :: forall e s m a. (MonadIO m, MonadCatch m, Monoid s, Exception e) => SafeBufferT s m a -> m s Source #

Runs a buffer and swallow exceptions of type e.

It purposefully does NOT catch async exceptions. To understand why, see Asynchronous exception handling in Haskell.

SafeBufferConcurrentT

newtype SafeBufferConcurrentT s m a Source #

Constructors

SafeBufferConcurrentT 

Fields

Instances

MonadWriter r m => MonadWriter r (SafeBufferConcurrentT s m) Source # 

Methods

writer :: (a, r) -> SafeBufferConcurrentT s m a #

tell :: r -> SafeBufferConcurrentT s m () #

listen :: SafeBufferConcurrentT s m a -> SafeBufferConcurrentT s m (a, r) #

pass :: SafeBufferConcurrentT s m (a, r -> r) -> SafeBufferConcurrentT s m a #

MonadState s m => MonadState s (SafeBufferConcurrentT s m) Source # 

Methods

get :: SafeBufferConcurrentT s m s #

put :: s -> SafeBufferConcurrentT s m () #

state :: (s -> (a, s)) -> SafeBufferConcurrentT s m a #

MonadError e m => MonadError e (SafeBufferConcurrentT s m) Source # 
(MonadIO m, Monoid s) => SafeBufferMonad s (SafeBufferConcurrentT s m) Source # 
MonadTrans (SafeBufferConcurrentT s) Source # 

Methods

lift :: Monad m => m a -> SafeBufferConcurrentT s m a #

Monad m => MonadReader (TVar s) (SafeBufferConcurrentT s m) Source # 

Methods

ask :: SafeBufferConcurrentT s m (TVar s) #

local :: (TVar s -> TVar s) -> SafeBufferConcurrentT s m a -> SafeBufferConcurrentT s m a #

reader :: (TVar s -> a) -> SafeBufferConcurrentT s m a #

Monad m => Monad (SafeBufferConcurrentT s m) Source # 
Functor m => Functor (SafeBufferConcurrentT s m) Source # 

Methods

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

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

MonadFix m => MonadFix (SafeBufferConcurrentT s m) Source # 

Methods

mfix :: (a -> SafeBufferConcurrentT s m a) -> SafeBufferConcurrentT s m a #

MonadFail m => MonadFail (SafeBufferConcurrentT s m) Source # 

Methods

fail :: String -> SafeBufferConcurrentT s m a #

Applicative m => Applicative (SafeBufferConcurrentT s m) Source # 
MonadZip m => MonadZip (SafeBufferConcurrentT s m) Source # 
MonadIO m => MonadIO (SafeBufferConcurrentT s m) Source # 

Methods

liftIO :: IO a -> SafeBufferConcurrentT s m a #

Alternative m => Alternative (SafeBufferConcurrentT s m) Source # 
MonadPlus m => MonadPlus (SafeBufferConcurrentT s m) Source # 
MonadThrow m => MonadThrow (SafeBufferConcurrentT s m) Source # 

Methods

throwM :: Exception e => e -> SafeBufferConcurrentT s m a #

MonadCatch m => MonadCatch (SafeBufferConcurrentT s m) Source # 
MonadMask m => MonadMask (SafeBufferConcurrentT s m) Source # 
MonadCont m => MonadCont (SafeBufferConcurrentT s m) Source # 

Methods

callCC :: ((a -> SafeBufferConcurrentT s m b) -> SafeBufferConcurrentT s m a) -> SafeBufferConcurrentT s m a #

runBufferConcurrently :: forall s m a b. (MonadIO m, MonadMask m, Monoid s) => (s -> m b) -> SafeBufferConcurrentT s m a -> m a Source #

Runs a buffer that can be safely shared accross threads and applies a given function to it. If an exception occurs while running the buffer, the function still runs before the exception is rethrown.

tryRunBufferConcurrently :: forall e s m a. (MonadIO m, MonadCatch m, Monoid s, Exception e) => SafeBufferConcurrentT s m a -> m (s, Either e a) Source #

Runs a buffer that can be safely shared accross threads and returns it, along with either an exception or the computation's result.

It purposefully does NOT catch async exceptions. To understand why, see Asynchronous exception handling in Haskell.

execBufferConcurrently :: forall e s m a. (MonadIO m, MonadCatch m, Monoid s, Exception e) => SafeBufferConcurrentT s m a -> m s Source #

Runs a buffer that can be safely shared accross threads, and swallows exceptions of type e.

It purposefully does NOT catch async exceptions. To understand why, see Asynchronous exception handling in Haskell.