diff --git a/core/Control/Rematch.hs b/core/Control/Rematch.hs index d32a57c..bf95ccb 100644 --- a/core/Control/Rematch.hs +++ b/core/Control/Rematch.hs @@ -44,6 +44,7 @@ import Control.Applicative (liftA2) import Data.List ( nub , intercalate ) import qualified Data.Maybe as M +import qualified Data.Foldable as F import Control.Rematch.Run import Control.Rematch.Formatting @@ -129,25 +130,26 @@ andAlso m m' = Matcher { | otherwise = "You've found a bug in rematch!" -- |Matches if every item in the input list passes a matcher -everyItem :: Matcher a -> Matcher [a] +everyItem :: Foldable f => Matcher a -> Matcher (f a) everyItem m = Matcher { match = all (match m) , description = "everyItem(" ++ description m ++ ")" - , describeMismatch = describeList "" . map (describeMismatch m) . filter (not . match m) + , describeMismatch = describeList "" . fmap (describeMismatch m) . + filter (not . match m) . F.toList } -- |Matches if any of the items in the input list passes the provided matcher -hasItem :: Matcher a -> Matcher [a] +hasItem :: Foldable f => Matcher a -> Matcher (f a) hasItem m = Matcher { match = any (match m) , description = "hasItem(" ++ description m ++ ")" - , describeMismatch = go + , describeMismatch = go . F.toList } where go [] = "got an empty list: []" go as = describeList "" (map (describeMismatch m) as) -- |Matches if the input list is empty -isEmpty :: (Show a) => Matcher [a] +isEmpty :: (Show (f a), Foldable f) => Matcher (f a) isEmpty = Matcher { match = null , description = "isEmpty" @@ -155,7 +157,7 @@ isEmpty = Matcher { } -- |Matches if the input list has the required size -hasSize :: (Show a) => Int -> Matcher [a] +hasSize :: (Show (f a), Foldable f) => Int -> Matcher (f a) hasSize n = Matcher { match = ((== n) . length) , description = "hasSize(" ++ show n ++ ")" diff --git a/core/rematch.cabal b/core/rematch.cabal index cfd3115..4714edd 100644 --- a/core/rematch.cabal +++ b/core/rematch.cabal @@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: rematch -version: 0.2.0.0 +version: 0.2.1.0 synopsis: A simple api for matchers description: Rematch is a simple library of matchers, which express rules @@ -26,9 +26,10 @@ build-type: Simple cabal-version: >=1.8 library - exposed-modules: Control.Rematch, Control.Rematch.Formatting, Control.Rematch.Run - build-depends: base >= 4.5.0 && < 5 + exposed-modules: Control.Rematch, Control.Rematch.Formatting, + Control.Rematch.Run, Control.Rematch.Traversable + build-depends: base >= 4.8 && < 5 test-suite tests - build-depends: base >= 4.5.0 && < 5, hspec >= 1.4, HUnit >= 1.2 + build-depends: base >= 4.8 && < 5, hspec >= 1.4, HUnit >= 1.2 type: exitcode-stdio-1.0 main-is: Main.hs