summaryrefslogtreecommitdiff
path: root/Utility/Monad.hs
diff options
context:
space:
mode:
authorGravatar guilhem <guilhem@fripost.org>2013-08-26 02:47:49 +0200
committerGravatar Joey Hess <joey@kitenet.net>2013-08-25 21:02:13 -0400
commitdf48567279fa504ca31d9f4f25b06066f08d1128 (patch)
tree8b40f2d55abe2e74f870696db131536c43794116 /Utility/Monad.hs
parentb20ea840b89f7b1584b3cadcc195508ff824ad54 (diff)
Speed up the 'unused' command.
Instead of populating the second-level Bloom filter with every key referenced in every Git reference, consider only those which differ from what's referenced in the index. Incidentaly, unlike with its old behavior, staged modifications/deletion/... will now be detected by 'unused'. Credits to joeyh for the algorithm. :-)
Diffstat (limited to 'Utility/Monad.hs')
-rw-r--r--Utility/Monad.hs12
1 files changed, 11 insertions, 1 deletions
diff --git a/Utility/Monad.hs b/Utility/Monad.hs
index b66419f76..4f5a6d244 100644
--- a/Utility/Monad.hs
+++ b/Utility/Monad.hs
@@ -8,7 +8,7 @@
module Utility.Monad where
import Data.Maybe
-import Control.Monad (liftM)
+import Control.Monad
{- Return the first value from a list, if any, satisfying the given
- predicate -}
@@ -53,6 +53,16 @@ ma <&&> mb = ifM ma ( mb , return False )
infixr 3 <&&>
infixr 2 <||>
+{- Left-to-right Kleisli composition with a pure left/right hand side. -}
+(*>=>) :: Monad m => (a -> b) -> (b -> m c) -> (a -> m c)
+f *>=> g = return . f >=> g
+
+(>=*>) :: Monad m => (a -> m b) -> (b -> c) -> (a -> m c)
+f >=*> g = f >=> return . g
+
+{- Same fixity as >=> and <=< -}
+infixr 1 *>=>, >=*>
+
{- Runs an action, passing its value to an observer before returning it. -}
observe :: Monad m => (a -> m b) -> m a -> m a
observe observer a = do