packages feed

monad-extras 0.5.3 → 0.5.4

raw patch · 2 files changed

+21/−2 lines, 2 files

Files

Control/Monad/Extra.hs view
@@ -11,10 +11,11 @@ import Control.Monad.Base import Control.Monad.IO.Class import Control.Monad.Morph+import Control.Monad.STM import Control.Monad.Trans.Cont import Control.Monad.Trans.Control-import Control.Monad.STM import Data.IORef+import Data.Maybe (catMaybes)  -- | Synonym for @return ()@. skip :: Monad m => m ()@@ -77,6 +78,10 @@ liftMaybe :: MonadPlus m => Maybe a -> m a liftMaybe = maybe mzero return +-- | A monadic version of @mapMaybe :: (a -> Maybe b) -> [a] -> [b]@.+mapMaybeM :: (Monad m, Functor m) => (a -> m (Maybe b)) -> [a] -> m [b]+mapMaybeM f xs = catMaybes <$> mapM f xs+ -- | A transformer-friendly version of 'atomically'. atomicallyM :: MonadIO m => STM a -> m a atomicallyM = liftIO . atomically@@ -194,6 +199,20 @@         else do             as <- sequenceUntil p ms             return (a:as)++-- | Draw monadic actions from a list until one of them yields a value+--   failing the predicate, and then return all the passing values+--   (discarding the final, failing value) in a list within that+--   monad.+sequenceWhile :: Monad m => (a -> Bool) -> [m a] -> m [a]+sequenceWhile _ [] = return []+sequenceWhile p (m:ms) = do+    a <- m+    if p a+        then do+            as <- sequenceWhile p ms+            return (a:as)+        else return []  -- | A type wrapper for composing monad transformers.  This is very similar to --   'Data.Functor.Compose', just one level up.
monad-extras.cabal view
@@ -1,5 +1,5 @@ name:           monad-extras-version:        0.5.3+version:        0.5.4 synopsis:       Extra utility functions for working with monads -- description: homepage:       http://github.com/jwiegley/monad-extras