Commits

Bryan O'Sullivan committed f869536

Rename count to countChar.

Comments (0)

Files changed (6)

     , findIndices
     , elemIndex
     , elemIndices
-    , count
+    , countChar
 
     -- * Zipping and unzipping
     , zip
 elemIndices c t = S.elemIndices c (stream t)
 {-# INLINE elemIndices #-}
 
--- | /O(n)/ The 'count' function returns the number of times the query
--- element appears in the given 'Text'. Subject to fusion.
-count :: Char -> Text -> Int
-count c t = S.count c (stream t)
-{-# INLINE count #-}
+-- | /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
+countChar c t = S.countChar c (stream t)
+{-# INLINE countChar #-}
 
 -------------------------------------------------------------------------------
 -- * Zipping

Data/Text/Fusion.hs

     , findIndexOrEnd
     , elemIndex
     , elemIndices
-    , count
+    , countChar
     ) where
 
 import Prelude (Bool(..), Char, Eq(..), Maybe(..), Monad(..), Int,
 
 -- | /O(n)/ The 'count' function returns the number of times the query
 -- element appears in the given stream.
-count :: Char -> Stream Char -> Int
-count = S.countI
-{-# INLINE [0] count #-}
+countChar :: Char -> Stream Char -> Int
+countChar = S.countCharI
+{-# INLINE [0] countChar #-}

Data/Text/Fusion/Common.hs

     , findIndicesI
     , elemIndexI
     , elemIndicesI
-    , countI
+    , countCharI
 
     -- * Zipping and unzipping
     , zipWith
                  | otherwise -> loop (i+1) s'
 {-# INLINE [0] elemIndicesI #-}
 
--- | /O(n)/ The 'count' function returns the number of times the query
--- element appears in the given stream.
-countI :: Integral a => Char -> Stream Char -> a
-countI a (Stream next s0 _len) = loop 0 s0
+-- | /O(n)/ The 'countCharI' function returns the number of times the
+-- query element appears in the given stream.
+countCharI :: Integral a => Char -> Stream Char -> a
+countCharI a (Stream next s0 _len) = loop 0 s0
   where
     loop !i !s = case next s of
       Done                   -> i
       Skip    s'             -> loop i s'
       Yield x s' | a == x    -> loop (i+1) s'
                  | otherwise -> loop i s'
-{-# INLINE [0] countI #-}
+{-# INLINE [0] countCharI #-}
 
 streamError :: String -> String -> a
 streamError func msg = P.error $ "Data.Text.Fusion.Common." ++ func ++ ": " ++ msg

Data/Text/Lazy.hs

     , findIndices
     , elemIndex
     , elemIndices
-    , count
+    , countChar
 
     -- * Zipping and unzipping
     , zip
 elemIndices c t = S.elemIndices c (stream t)
 {-# INLINE elemIndices #-}
 
--- | /O(n)/ The 'count' function returns the number of times the query
--- element appears in the given 'Text'. This function is subject to
--- fusion.
-count :: Char -> Text -> Int64
-count c t = S.count c (stream t)
-{-# INLINE count #-}
+-- | /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,

Data/Text/Lazy/Fusion.hs

     , findIndices
     , elemIndex
     , elemIndices
-    , count
+    , countChar
     ) where
 
 import Prelude hiding (length)
 
 -- | /O(n)/ The 'count' function returns the number of times the query
 -- element appears in the given stream.
-count :: Char -> Stream Char -> Int64
-count = S.countI
-{-# INLINE [0] count #-}
+countChar :: Char -> Stream Char -> Int64
+countChar = S.countCharI
+{-# INLINE [0] countChar #-}

tests/Properties.hs

 tl_split_i t      = id `eq` (TL.intercalate t . 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.count c)
+t_splitWith_count c = (L.length . T.splitWith (==c)) `eq` ((1+) . T.countChar 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)
 
 sf_elemIndices p c= (L.elemIndices c . L.filter p) `eqP` (S.elemIndices c . S.filter p)
 t_elemIndices c   = L.elemIndices c`eqP` T.elemIndices c
 tl_elemIndices c  = (fmap fromIntegral . L.elemIndices c) `eqP` TL.elemIndices c
-sf_count p c      = (L.length . L.elemIndices c . L.filter p) `eqP` (S.count c . S.filter p)
-t_count c         = (L.length . L.elemIndices c) `eqP` T.count c
-tl_count c        = (fromIntegral . L.length . L.elemIndices c) `eqP` TL.count c
+sf_count p c      = (L.length . L.elemIndices c . L.filter p) `eqP` (S.countChar c . S.filter p)
+t_count c         = (L.length . L.elemIndices c) `eqP` T.countChar c
+tl_count 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)