diff options
author | Joey Hess <joey@kitenet.net> | 2012-01-21 02:24:12 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2012-01-21 02:49:32 -0400 |
commit | 183bdacca219065e6a888385e3bf309708e827ec (patch) | |
tree | 6ee1c6ba8b75de8b182fd969b612a8557f72360c /Utility/Monad.hs | |
parent | eb9001044f3db682236d1007aded58f47109d6a6 (diff) |
treak
Diffstat (limited to 'Utility/Monad.hs')
-rw-r--r-- | Utility/Monad.hs | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/Utility/Monad.hs b/Utility/Monad.hs index 95964361e..28aa33ee8 100644 --- a/Utility/Monad.hs +++ b/Utility/Monad.hs @@ -12,7 +12,7 @@ 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 :: Monad m => (a -> m Bool) -> [a] -> m (Maybe a) firstM _ [] = return Nothing firstM p (x:xs) = do q <- p x @@ -22,20 +22,20 @@ firstM p (x:xs) = do {- Returns true if any value in the list satisfies the predicate, - stopping once one is found. -} -anyM :: (Monad m) => (a -> m Bool) -> [a] -> m Bool +anyM :: Monad m => (a -> m Bool) -> [a] -> m Bool anyM p = liftM isJust . firstM p {- Runs an action on values from a list until it succeeds. -} -untilTrue :: (Monad m) => [a] -> (a -> m Bool) -> m Bool +untilTrue :: Monad m => [a] -> (a -> m Bool) -> m Bool untilTrue = flip anyM {- Runs an action, passing its value to an observer before returning it. -} -observe :: (Monad m) => (a -> m b) -> m a -> m a +observe :: Monad m => (a -> m b) -> m a -> m a observe observer a = do r <- a _ <- observer r return r {- b `after` a runs first a, then b, and returns the value of a -} -after :: (Monad m) => m b -> m a -> m a +after :: Monad m => m b -> m a -> m a after = observe . const |