on master help sign in
Monoid instance for pattern
ecf4c64Jasper Van der Jeugt
src/Hakyll/Core/Identifier/Pattern.hs+7−1
@@ -47,7 +47,7 @@ import Data.List (isPrefixOf, inits, tails)
47import Control.Arrow ((&&&), (>>>))
47import Control.Arrow ((&&&), (>>>))
48import Control.Monad (msum)
48import Control.Monad (msum)
49import Data.Maybe (isJust)
49import Data.Maybe (isJust)
50−import Data.Monoid (mempty, mappend)
50+import Data.Monoid (Monoid, mempty, mappend)
51
51
52import GHC.Exts (IsString, fromString)
52import GHC.Exts (IsString, fromString)
53
53
@@ -68,6 +68,12 @@ data Pattern = Glob [GlobComponent]
68instance IsString Pattern where
68instance IsString Pattern where
69 fromString = parseGlob
69 fromString = parseGlob
70
70
71+instance Monoid Pattern where
72+ mempty = Predicate (const True)
73+ g@(Glob _) `mappend` x = Predicate (matches g) `mappend` x
74+ x `mappend` g@(Glob _) = x `mappend` Predicate (matches g)
75+ Predicate f `mappend` Predicate g = Predicate $ \i -> f i && g i
76+
71-- | Parse a pattern from a string
77-- | Parse a pattern from a string
72--
78--
73parseGlob :: String -> Pattern
79parseGlob :: String -> Pattern