Popularity
2.6
Declining
Activity
0.0
Stable
1
3
0
Monthly Downloads: 10
Programming language: Haskell
License: BSD 3-clause "New" or "Revised" License
safe-buffer-monad alternatives and similar packages
Based on the "safe" category.
Alternatively, view safe-buffer-monad alternatives based on common mentions on social networks and blogs.
-
safe-exceptions-checked
Safe, checked exceptions -
lawful
A constraint to assert that your typeclass instances are lawful
Build time-series-based applications quickly and at scale.
InfluxDB is the Time Series Platform where developers build real-time applications for analytics, IoT and cloud-native services. Easy to start, it is available in the cloud or on-premises.
Promo
www.influxdata.com
Do you think we are missing an alternative of safe-buffer-monad or a related project?
README
safe-buffer-monad
A monadic buffer resilient to exceptions.
The SafeBufferMonad
typeclass models a buffer that you can write things to. If an exception is thrown,
you'll still be able to proccess the contents of the buffer up to the point where the computation was interrupted.
class Monad m => SafeBufferMonad s m | m -> s where
readBuffer :: m s
writeBuffer :: s -> m ()
clearBuffer :: m s
modifyBuffer :: (s -> s) -> m ()
The buffer can be run using one of these 6 functions:
runBuffer
/runBufferConcurrently
tryRunBuffer
/tryRunBufferConcurrently
execBuffer
/execBufferConcurrently
{-# LANGUAGE FlexibleContexts #-}
import SafeBuffer
import Data.List (intercalate)
go :: (SafeBufferMonad [String] m, MonadIO m) => m String
go = do
writeBuffer ["line 1"]
writeBuffer ["line 2"]
liftIO $ putStrLn "brace for impact!"
liftIO $ throwIO $ userError "boom"
writeBuffer ["line 3"]
pure "done!"
main = runBuffer (appendFile "log.txt" . intercalate "\n") go
λ> main
brace for impact!
*** Exception: user error (boom)
λ> :! tail log.txt
line 1
line 2