summaryrefslogtreecommitdiff
path: root/Annex.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-11-08 15:34:10 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-11-08 16:27:20 -0400
commitbf460a0a98d7e4c7f4eac525fcf300629db582b6 (patch)
treebff7cd09529c40fa8cb76fd92428cc41e24ad808 /Annex.hs
parent2ff8915365099501382183af9855e739fc234861 (diff)
reorder repo parameters last
Many functions took the repo as their first parameter. Changing it consistently to be the last parameter allows doing some useful things with currying, that reduce boilerplate. In particular, g <- gitRepo is almost never needed now, instead use inRepo to run an IO action in the repo, and fromRepo to get a value from the repo. This also provides more opportunities to use monadic and applicative combinators.
Diffstat (limited to 'Annex.hs')
-rw-r--r--Annex.hs16
1 files changed, 14 insertions, 2 deletions
diff --git a/Annex.hs b/Annex.hs
index 2c6402ac3..501e54c66 100644
--- a/Annex.hs
+++ b/Annex.hs
@@ -17,7 +17,9 @@ module Annex (
eval,
getState,
changeState,
- gitRepo
+ gitRepo,
+ inRepo,
+ fromRepo,
) where
import Control.Monad.IO.Control
@@ -114,6 +116,16 @@ getState = gets
changeState :: (AnnexState -> AnnexState) -> Annex ()
changeState = modify
-{- Returns the git repository being acted on -}
+{- Returns the annex's git repository. -}
gitRepo :: Annex Git.Repo
gitRepo = getState repo
+
+{- Runs an IO action in the annex's git repository. -}
+inRepo :: (Git.Repo -> IO a) -> Annex a
+inRepo a = do
+ g <- gitRepo
+ liftIO $ a g
+
+{- Extracts a value from the annex's git repisitory. -}
+fromRepo :: (Git.Repo -> a) -> Annex a
+fromRepo a = a <$> gitRepo