packages feed

cond 0.0.1 → 0.0.2

raw patch · 2 files changed

+32/−5 lines, 2 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Control.Cond: until1M :: Monad m => m Bool -> m a -> m a
+ Control.Cond: untilM :: Monad m => m Bool -> m a -> m ()
+ Control.Cond: while1M :: Monad m => m Bool -> m a -> m a
+ Control.Cond: whileM :: Monad m => m Bool -> m a -> m ()

Files

cond.cabal view
@@ -1,6 +1,6 @@ Name: cond-Version: 0.0.1-Synopsis: Basic conditional operators with monadic variants.+Version: 0.0.2+Synopsis: Basic conditional and boolean operators with monadic variants. Category: Control, Logic, Monad License: BSD3 License-File: LICENSE@@ -11,8 +11,8 @@ Build-Type: Simple Description:   A very simple library implementing various conditional operations, as well-  as some functions for dealing with conditions in monadic code. Feel free-  to send ideas and suggestions for new conditional operators to the+  as some functions for dealing with conditions and loops in monadic code.+  Feel free to send ideas and suggestions for new conditional operators to the   maintainer.   source-repository head
src/Control/Cond.hs view
@@ -10,9 +10,12 @@        , ifM, (<||>), (<&&>), notM, condM, condPlusM          -- * Lifted guard and when        , guardM, whenM, unlessM +         -- * Monadic looping conditionals+       , whileM, untilM, while1M, until1M        ) where-import Control.Monad ( MonadPlus (mzero), guard, liftM ) +import Control.Monad+ infixr 1 ?? infixr 2 <||> infixr 3 <&&>@@ -55,6 +58,9 @@ -- |Composes a predicate function and 2 functions into a single -- function. The first function is called when the predicate yields True, the -- second when the predicate yields False.+--+-- Note that after importing "Control.Monad.Instances", 'select' becomes a  +-- special case of 'ifM'. select :: (a -> Bool) -> (a -> b) -> (a -> b) -> (a -> b) select p a b x = if' (p x) (a x) (b x) {-# INLINE select #-}@@ -109,3 +115,24 @@ guardM :: MonadPlus m => m Bool -> m () guardM = (guard =<<) {-# INLINE guardM #-}++-- |A monadic while loop.+whileM :: Monad m => m Bool -> m a -> m ()+whileM p m = whenM p (m >> whileM p m) ++-- |A monadic while loop with a negated conditional.+untilM :: Monad m => m Bool -> m a -> m ()+untilM p = whileM (notM p)+{-# INLINE untilM #-}++-- |A monadic do-while loop. The monadic action is guaranteed to be executed +-- once. Because of this, we can also return the result of the last execution +-- of the loop.+while1M :: Monad m => m Bool -> m a -> m a+while1M p m = do a <- m+                 ifM p (while1M p m) (return a)++-- |A negated do-while loop.+until1M :: Monad m => m Bool -> m a -> m a+until1M p = while1M (notM p)+{-# INLINE until1M #-}