summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTonyMorris <>2011-01-18 08:10:46 (GMT)
committerLuite Stegeman <luite@luite.com>2011-01-18 08:10:46 (GMT)
commit6bff0b522de330a42d90f3a64d7ad590673ed0ac (patch)
tree0fb0b6047263c4b2ab2b815b4cc2cbdecae91e68
parente709034e391d21b29401fc001c8258eb0f40eb31 (diff)
version 0.0.20.0.2
-rw-r--r--UtilityTM.cabal2
-rw-r--r--src/Control/Monad/TM.hs44
2 files changed, 38 insertions, 8 deletions
diff --git a/UtilityTM.cabal b/UtilityTM.cabal
index c2b6eb4..01ea20e 100644
--- a/UtilityTM.cabal
+++ b/UtilityTM.cabal
@@ -1,5 +1,5 @@
Name: UtilityTM
-Version: 0.0.1
+Version: 0.0.2
License: BSD3
License-File: LICENSE
Author: Tony Morris <ʇǝu˙sıɹɹoɯʇ@ןןǝʞsɐɥ>
diff --git a/src/Control/Monad/TM.hs b/src/Control/Monad/TM.hs
index 9b17ecf..5b784dc 100644
--- a/src/Control/Monad/TM.hs
+++ b/src/Control/Monad/TM.hs
@@ -1,8 +1,10 @@
-- | Monadic combinators missing from the standard library
module Control.Monad.TM
(
- (.>>=.)
-, (.=<<.)
+ (.=<<.)
+, (.>>=.)
+, anyM
+, allM
) where
import Data.Traversable
@@ -10,19 +12,47 @@ import Control.Monad hiding (mapM)
import Prelude hiding (mapM)
-- | Lifting bind into a monad. Often denoted /concatMapM/.
-(.>>=.) ::
+(.=<<.) ::
(Monad q, Monad m, Traversable m) =>
(a -> q (m b))
-> m a
-> q (m b)
-(.>>=.) f =
+(.=<<.) f =
liftM join . mapM f
-- | Lifting bind into a monad. Often denoted /concatMapM/.
-(.=<<.) ::
+(.>>=.) ::
(Monad q, Monad m, Traversable m) =>
m a
-> (a -> q (m b))
-> q (m b)
-(.=<<.) =
- flip (.>>=.)
+(.>>=.) =
+ flip (.=<<.)
+
+-- | Existential quantification.
+anyM ::
+ Monad m =>
+ (a -> m Bool)
+ -> [a]
+ -> m Bool
+anyM _ [] =
+ return False
+anyM f (a:as) =
+ do z <- f a
+ if z
+ then return True
+ else anyM f as
+
+-- | Universal quantification.
+allM ::
+ Monad m =>
+ (a -> m Bool)
+ -> [a]
+ -> m Bool
+allM _ [] =
+ return True
+allM f (a:as) =
+ do z <- f a
+ if z
+ then allM f as
+ else return False