diff options
author | Daniel P. Wright <dani@dpwright.com> | 2015-01-03 22:55:51 +0900 |
---|---|---|
committer | Daniel P. Wright <dani@dpwright.com> | 2015-01-03 22:55:51 +0900 |
commit | b36232e05ebe7fbde708364a2587ba91287010cd (patch) | |
tree | 782af2818ba4edcad1ab5c2458053ddb3abedcff /src | |
parent | d0af1024d008113347183024df41c739d7644c02 (diff) | |
download | hakyll-b36232e05ebe7fbde708364a2587ba91287010cd.tar.gz |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/Hakyll/Core/Rules.hs | 21 |
1 files changed, 9 insertions, 12 deletions
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 -------------------------------------------------------------------------------- |