Commits

Bryan O'Sullivan committed 9526857

Remove countChar from the public API.

Comments (0)

Files changed (3)

     , elemIndex
     , elemIndices
     , count
-    , countChar
 
     -- * Zipping and unzipping
     , zip
                  | otherwise          = search (unsafeTail s)
 {-# INLINE [1] count #-}
 
+{-# RULES
+"TEXT count/singleton -> countChar" [~1] forall c t.
+    count (singleton c) t = countChar c t
+  #-}
+
 -- | /O(n)/ The 'countChar' function returns the number of times the
 -- query element appears in the given 'Text'. Subject to fusion.
 countChar :: Char -> Text -> Int

Data/Text/Lazy.hs

     , elemIndex
     , elemIndices
     , count
-    , countChar
 
     -- * Zipping and unzipping
     , zip
                  | otherwise          = search (tail s)
 {-# INLINE [1] count #-}
 
+{-# RULES
+"LAZY TEXT count/singleton -> countChar" [~1] forall c t.
+    count (singleton c) t = countChar c t
+  #-}
+
 -- | /O(n)/ The 'countChar' function returns the number of times the
 -- query element appears in the given 'Text'. This function is subject
 -- to fusion.
 countChar :: Char -> Text -> Int64
 countChar c t = S.countChar c (stream t)
-{-# INLINE countChar #-}
 
 -- | /O(n)/ 'zip' takes two 'Text's and returns a list of
 -- corresponding pairs of bytes. If one input 'Text' is short,

tests/Properties.hs

 tl_splitTimesEnd_split (NotEmpty t) = TL.splitTimesEnd maxBound t `eq` TL.split t
 
 t_splitWith p     = splitWith p `eqP` (map unpackS . T.splitWith p)
-t_splitWith_count c = (L.length . T.splitWith (==c)) `eq` ((1+) . T.countChar c)
+t_splitWith_count c = (L.length . T.splitWith (==c)) `eq` ((1+) . T.count (T.singleton c))
 t_splitWith_split c = T.splitWith (==c) `eq` T.split (T.singleton c)
 tl_splitWith p    = splitWith p `eqP` (map unpackS . TL.splitWith p)
 
 tl_elemIndices c  = (fmap fromIntegral . L.elemIndices c) `eqP` TL.elemIndices c
 t_count t         = (subtract 1 . L.length . T.split t) `eq` T.count t
 tl_count t        = (subtract 1 . L.genericLength . TL.split t) `eq` TL.count t
-sf_countChar p c  = (L.length . L.elemIndices c . L.filter p) `eqP` (S.countChar c . S.filter p)
-t_countChar c     = (L.length . L.elemIndices c) `eqP` T.countChar c
-tl_countChar c    = (fromIntegral . L.length . L.elemIndices c) `eqP` TL.countChar c
 t_zip s           = L.zip s `eqP` T.zip (packS s)
 tl_zip s          = L.zip s `eqP` TL.zip (packS s)
 sf_zipWith p c s  = (L.zipWith c (L.filter p s) . L.filter p) `eqP` (unpackS . S.zipWith c (S.filter p $ packS s) . S.filter p)
     testProperty "t_elemIndices" t_elemIndices,
     testProperty "tl_elemIndices" tl_elemIndices,
     testProperty "t_count" t_count,
-    testProperty "tl_count" tl_count,
-    testProperty "sf_countChar" sf_countChar,
-    testProperty "t_countChar" t_countChar,
-    testProperty "tl_countChar" tl_countChar
+    testProperty "tl_count" tl_count
   ],
 
   testGroup "zips" [