packages feed

monad-loops 0.3 → 0.3.0.1

raw patch · 2 files changed

+20/−1 lines, 2 filesPVP: minor bump suggested

API additions: PVP suggests at least a minor version bump

API changes (from Hackage documentation)

+ Control.Monad.Loops: iterateUntil :: (Monad m) => (a -> Bool) -> m a -> m a
+ Control.Monad.Loops: iterateWhile :: (Monad m) => (a -> Bool) -> m a -> m a

Files

monad-loops.cabal view
@@ -1,5 +1,5 @@ name:                   monad-loops-version:                0.3+version:                0.3.0.1 stability:              provisional license:                BSD3 license-file:           LICENSE@@ -9,6 +9,7 @@  author:                 James Cook <mokus@deepbondi.net> maintainer:             James Cook <mokus@deepbondi.net>+homepage:               http://code.haskell.org/~mokus/monad-loops  category:               Control synopsis:               Monadic loops
src/Control/Monad/Loops.hs view
@@ -132,6 +132,15 @@                         whileM_ p f                 else return () +-- |Execute an action repeatedly until its result fails to satisfy a predicate,+-- and return that result (discarding all others).+iterateWhile :: Monad m => (a -> Bool) -> m a -> m a+iterateWhile p x = do+    y <- x+    if p y+        then iterateWhile p x+        else return y+ {-# SPECIALIZE untilM  :: IO a -> IO Bool -> IO [a] #-} {-# SPECIALIZE untilM' :: Monad m => m a -> m Bool -> m [a] #-} {-# SPECIALIZE untilM' :: IO a -> IO Bool -> IO [a] #-}@@ -167,6 +176,15 @@ {-# SPECIALIZE whileJust' :: Monad m => m (Maybe a) -> (a -> m b) -> m [b] #-} {-# SPECIALIZE whileJust' :: IO (Maybe a) -> (a -> IO b) -> IO [b] #-} {-# SPECIALIZE whileJust_ :: IO (Maybe a) -> (a -> IO b) -> IO () #-}++-- |Execute an action repeatedly until its result satisfies a predicate,+-- and return that result (discarding all others).+iterateUntil :: Monad m => (a -> Bool) -> m a -> m a+iterateUntil p x = do+    y <- x+    if p y+        then return y+        else iterateUntil p x  -- |As long as the supplied "Maybe" expression returns "Just _", the loop -- body will be called and passed the value contained in the 'Just'.  Results