on master help sign in
Refactor match and matchMetadata code into matchInternal
b36232eDaniel P. Wright
src/Hakyll/Core/Rules.hs+9−12
@@ -121,28 +121,25 @@ flush = Rules $ do
121
121
122
122
123--------------------------------------------------------------------------------
123--------------------------------------------------------------------------------
124−match :: Pattern -> Rules () -> Rules ()
124+matchInternal :: Pattern -> Rules [Identifier] -> Rules () -> Rules ()
125−match pattern rules = do
125+matchInternal pattern getIDs rules = do
126 tellPattern pattern
126 tellPattern pattern
127 flush
127 flush
128− ids <- getMatches pattern
128+ ids <- getIDs
129 tellResources ids
129 tellResources ids
130 Rules $ local (setMatches ids) $ unRules $ rules >> flush
130 Rules $ local (setMatches ids) $ unRules $ rules >> flush
131 where
131 where
132 setMatches ids env = env {rulesMatches = ids}
132 setMatches ids env = env {rulesMatches = ids}
133
133
134+--------------------------------------------------------------------------------
135+match :: Pattern -> Rules () -> Rules ()
136+match pattern = matchInternal pattern $ getMatches pattern
137+
134
138
135--------------------------------------------------------------------------------
139--------------------------------------------------------------------------------
136matchMetadata :: Pattern -> (Metadata -> Bool) -> Rules () -> Rules ()
140matchMetadata :: Pattern -> (Metadata -> Bool) -> Rules () -> Rules ()
137−matchMetadata pattern metadataPred rules = do
141+matchMetadata pattern metadataPred = matchInternal pattern $
138− tellPattern pattern
139− flush
140− idsAndMetadata <- getAllMetadata pattern
141− let ids = map fst . filter (metadataPred . snd) $ idsAndMetadata
142+ map fst . filter (metadataPred . snd) <$> getAllMetadata pattern
142− tellResources ids
143− Rules $ local (setMatches ids) $ unRules $ rules >> flush
144− where
145− setMatches ids env = env {rulesMatches = ids}
146
143
147
144
148--------------------------------------------------------------------------------
145--------------------------------------------------------------------------------