@@ -8,8 +8,10 @@ module Hakyll.Core.Compiler
88 , getRoute
99 , getResourceString
1010 , fromDependency
11+ , require_
1112 , require
1213 , requireA
14+ , requireAll_
1315 , requireAll
1416 , requireAllA
1517 , cached
@@ -17,11 +19,11 @@ module Hakyll.Core.Compiler
1719 ) where
1820
1921import Prelude hiding ((.), id)
20−import Control.Arrow ((>>>))
22+import Control.Arrow ((>>>), (&&&), arr)
2123import Control.Applicative ((<$>))
2224import Control.Monad.Reader (ask)
2325import Control.Monad.Trans (liftIO)
24−import Control.Category (Category, (.))
26+import Control.Category (Category, (.), id)
2527import Data.Maybe (fromMaybe)
2628
2729import Data.Binary (Binary)
@@ -85,7 +87,7 @@ getResourceString = getIdentifier >>> getResourceString'
8587-- | Auxiliary: get a dependency
8688--
8789getDependency :: (Binary a, Writable a, Typeable a)
88− => Identifier -> CompilerM a
90+ => Identifier -> CompilerM a
8991getDependency identifier = CompilerM $ do
9092 store <- compilerStore <$> ask
9193 fmap (fromMaybe error') $ liftIO $
@@ -96,6 +98,15 @@ getDependency identifier = CompilerM $ do
9698 ++ " not found in the cache, the cache might be corrupted or"
9799 ++ " the item you are referring to might not exist"
98100
101+
102+-- | Variant of 'require' which drops the current value
103+--
104+require_ :: (Binary a, Typeable a, Writable a)
105+ => Identifier
106+ -> Compiler b a
107+require_ identifier =
108+ fromDependency identifier >>> fromJob (const $ getDependency identifier)
109+
99110-- | Require another target. Using this function ensures automatic handling of
100111-- dependencies
101112--
@@ -103,12 +114,7 @@ require :: (Binary a, Typeable a, Writable a)
103114 => Identifier
104115 -> (b -> a -> c)
105116 -> Compiler b c
106−require identifier f =
107− fromDependency identifier >>> fromJob require'
108− where
109− require' x = do
110− y <- getDependency identifier
111− return $ f x y
117+require identifier = requireA identifier . arr . uncurry
112118
113119-- | Arrow-based variant of 'require'
114120--
@@ -116,7 +122,19 @@ requireA :: (Binary a, Typeable a, Writable a)
116122 => Identifier
117123 -> Compiler (b, a) c
118124 -> Compiler b c
119−requireA identifier = (require identifier (,) >>>)
125+requireA identifier = (id &&& require_ identifier >>>)
126+
127+-- | Variant of 'requireAll' which drops the current value
128+--
129+requireAll_ :: (Binary a, Typeable a, Writable a)
130+ => Pattern
131+ -> Compiler b [a]
132+requireAll_ pattern = fromDependencies getDeps >>> fromJob requireAll_'
133+ where
134+ getDeps = matches pattern . resourceList
135+ requireAll_' = const $ CompilerM $ do
136+ deps <- getDeps . compilerResourceProvider <$> ask
137+ mapM (unCompilerM . getDependency) deps
120138
121139-- | Require a number of targets. Using this function ensures automatic handling
122140-- of dependencies
@@ -125,14 +143,7 @@ requireAll :: (Binary a, Typeable a, Writable a)
125143 => Pattern
126144 -> (b -> [a] -> c)
127145 -> Compiler b c
128−requireAll pattern f =
129− fromDependencies getDeps >>> fromJob requireAll'
130− where
131− getDeps = matches pattern . resourceList
132− requireAll' x = CompilerM $ do
133− deps <- getDeps . compilerResourceProvider <$> ask
134− items <- mapM (unCompilerM . getDependency) deps
135− return $ f x items
146+requireAll pattern = requireAllA pattern . arr . uncurry
136147
137148-- | Arrow-based variant of 'requireAll'
138149--
@@ -140,7 +151,7 @@ requireAllA :: (Binary a, Typeable a, Writable a)
140151 => Pattern
141152 -> Compiler (b, [a]) c
142153 -> Compiler b c
143−requireAllA pattern = (requireAll pattern (,) >>>)
154+requireAllA pattern = (id &&& requireAll_ pattern >>>)
144155
145156cached :: (Binary a, Typeable a, Writable a)
146157 => String