From b36232e05ebe7fbde708364a2587ba91287010cd Mon Sep 17 00:00:00 2001 From: "Daniel P. Wright" Date: Sat, 3 Jan 2015 22:55:51 +0900 Subject: Refactor match and matchMetadata code into matchInternal As per jaspervdj's request in #300, refactor the common code from match and matchMetadata into a single, unexported function. --- src/Hakyll/Core/Rules.hs | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'src/Hakyll/Core') diff --git a/src/Hakyll/Core/Rules.hs b/src/Hakyll/Core/Rules.hs index 1c8b93c..0766e58 100644 --- a/src/Hakyll/Core/Rules.hs +++ b/src/Hakyll/Core/Rules.hs @@ -121,28 +121,25 @@ flush = Rules $ do -------------------------------------------------------------------------------- -match :: Pattern -> Rules () -> Rules () -match pattern rules = do +matchInternal :: Pattern -> Rules [Identifier] -> Rules () -> Rules () +matchInternal pattern getIDs rules = do tellPattern pattern flush - ids <- getMatches pattern + ids <- getIDs tellResources ids Rules $ local (setMatches ids) $ unRules $ rules >> flush where setMatches ids env = env {rulesMatches = ids} +-------------------------------------------------------------------------------- +match :: Pattern -> Rules () -> Rules () +match pattern = matchInternal pattern $ getMatches pattern + -------------------------------------------------------------------------------- matchMetadata :: Pattern -> (Metadata -> Bool) -> Rules () -> Rules () -matchMetadata pattern metadataPred rules = do - tellPattern pattern - flush - idsAndMetadata <- getAllMetadata pattern - let ids = map fst . filter (metadataPred . snd) $ idsAndMetadata - tellResources ids - Rules $ local (setMatches ids) $ unRules $ rules >> flush - where - setMatches ids env = env {rulesMatches = ids} +matchMetadata pattern metadataPred = matchInternal pattern $ + map fst . filter (metadataPred . snd) <$> getAllMetadata pattern -------------------------------------------------------------------------------- -- cgit v1.2.3