diff options
author | Joey Hess <joey@kitenet.net> | 2011-10-16 00:31:25 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2011-10-16 00:50:12 -0400 |
commit | 23f2a12816e250f6780f80443ef6ec31c13fca9e (patch) | |
tree | 98de024aa2909caa39f82a76ccde182afef5093b /Utility/Monad.hs | |
parent | 91366c896d9c9cb4519b451a64ed4d1e0ff52cb3 (diff) |
broke up Utility
Diffstat (limited to 'Utility/Monad.hs')
-rw-r--r-- | Utility/Monad.hs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/Utility/Monad.hs b/Utility/Monad.hs new file mode 100644 index 000000000..9523e1716 --- /dev/null +++ b/Utility/Monad.hs @@ -0,0 +1,26 @@ +{- monadic stuff + - + - Copyright 2010-2011 Joey Hess <joey@kitenet.net> + - + - Licensed under the GNU GPL version 3 or higher. + -} + +module Utility.Monad where + +import Data.Maybe +import Control.Monad (liftM) + +{- Return the first value from a list, if any, satisfying the given + - predicate -} +firstM :: (Monad m) => (a -> m Bool) -> [a] -> m (Maybe a) +firstM _ [] = return Nothing +firstM p (x:xs) = do + q <- p x + if q + then return (Just x) + else firstM p xs + +{- Returns true if any value in the list satisfies the preducate, + - stopping once one is found. -} +anyM :: (Monad m) => (a -> m Bool) -> [a] -> m Bool +anyM p = liftM isJust . firstM p |