on master help sign in
Remove countChar from the public API.
4c25b63Bryan O'Sullivan
Data/Text.hs+5−1
@@ -157,7 +157,6 @@ module Data.Text
157 , elemIndex
157 , elemIndex
158 , elemIndices
158 , elemIndices
159 , count
159 , count
160− , countChar
161
160
162 -- * Zipping and unzipping
161 -- * Zipping and unzipping
163 , zip
162 , zip
@@ -1123,6 +1122,11 @@ count pat src0
1123 | otherwise = search (unsafeTail s)
1122 | otherwise = search (unsafeTail s)
1124{-# INLINE [1] count #-}
1123{-# INLINE [1] count #-}
1125
1124
1125+{-# RULES
1126+"TEXT count/singleton -> countChar" [~1] forall c t.
1127+ count (singleton c) t = countChar c t
1128+ #-}
1129+
1126-- | /O(n)/ The 'countChar' function returns the number of times the
1130-- | /O(n)/ The 'countChar' function returns the number of times the
1127-- query element appears in the given 'Text'. Subject to fusion.
1131-- query element appears in the given 'Text'. Subject to fusion.
1128countChar :: Char -> Text -> Int
1132countChar :: Char -> Text -> Int
Data/Text/Lazy.hs+5−2
@@ -160,7 +160,6 @@ module Data.Text.Lazy
160 , elemIndex
160 , elemIndex
161 , elemIndices
161 , elemIndices
162 , count
162 , count
163− , countChar
164
163
165 -- * Zipping and unzipping
164 -- * Zipping and unzipping
166 , zip
165 , zip
@@ -1132,12 +1131,16 @@ count pat src0
1132 | otherwise = search (tail s)
1131 | otherwise = search (tail s)
1133{-# INLINE [1] count #-}
1132{-# INLINE [1] count #-}
1134
1133
1134+{-# RULES
1135+"LAZY TEXT count/singleton -> countChar" [~1] forall c t.
1136+ count (singleton c) t = countChar c t
1137+ #-}
1138+
1135-- | /O(n)/ The 'countChar' function returns the number of times the
1139-- | /O(n)/ The 'countChar' function returns the number of times the
1136-- query element appears in the given 'Text'. This function is subject
1140-- query element appears in the given 'Text'. This function is subject
1137-- to fusion.
1141-- to fusion.
1138countChar :: Char -> Text -> Int64
1142countChar :: Char -> Text -> Int64
1139countChar c t = S.countChar c (stream t)
1143countChar c t = S.countChar c (stream t)
1140−{-# INLINE countChar #-}
1141
1144
1142-- | /O(n)/ 'zip' takes two 'Text's and returns a list of
1145-- | /O(n)/ 'zip' takes two 'Text's and returns a list of
1143-- corresponding pairs of bytes. If one input 'Text' is short,
1146-- corresponding pairs of bytes. If one input 'Text' is short,
tests/Properties.hs+2−8
@@ -397,7 +397,7 @@ t_splitTimesEnd_split (NotEmpty t) = T.splitTimesEnd maxBound t `eq` T.split t
397tl_splitTimesEnd_split (NotEmpty t) = TL.splitTimesEnd maxBound t `eq` TL.split t
397tl_splitTimesEnd_split (NotEmpty t) = TL.splitTimesEnd maxBound t `eq` TL.split t
398
398
399t_splitWith p = splitWith p `eqP` (map unpackS . T.splitWith p)
399t_splitWith p = splitWith p `eqP` (map unpackS . T.splitWith p)
400−t_splitWith_count c = (L.length . T.splitWith (==c)) `eq` ((1+) . T.countChar c)
400+t_splitWith_count c = (L.length . T.splitWith (==c)) `eq` ((1+) . T.count (T.singleton c))
401t_splitWith_split c = T.splitWith (==c) `eq` T.split (T.singleton c)
401t_splitWith_split c = T.splitWith (==c) `eq` T.split (T.singleton c)
402tl_splitWith p = splitWith p `eqP` (map unpackS . TL.splitWith p)
402tl_splitWith p = splitWith p `eqP` (map unpackS . TL.splitWith p)
403
403
@@ -480,9 +480,6 @@ t_elemIndices c = L.elemIndices c`eqP` T.elemIndices c
480tl_elemIndices c = (fmap fromIntegral . L.elemIndices c) `eqP` TL.elemIndices c
480tl_elemIndices c = (fmap fromIntegral . L.elemIndices c) `eqP` TL.elemIndices c
481t_count t = (subtract 1 . L.length . T.split t) `eq` T.count t
481t_count t = (subtract 1 . L.length . T.split t) `eq` T.count t
482tl_count t = (subtract 1 . L.genericLength . TL.split t) `eq` TL.count t
482tl_count t = (subtract 1 . L.genericLength . TL.split t) `eq` TL.count t
483−sf_countChar p c = (L.length . L.elemIndices c . L.filter p) `eqP` (S.countChar c . S.filter p)
484−t_countChar c = (L.length . L.elemIndices c) `eqP` T.countChar c
485−tl_countChar c = (fromIntegral . L.length . L.elemIndices c) `eqP` TL.countChar c
486t_zip s = L.zip s `eqP` T.zip (packS s)
483t_zip s = L.zip s `eqP` T.zip (packS s)
487tl_zip s = L.zip s `eqP` TL.zip (packS s)
484tl_zip s = L.zip s `eqP` TL.zip (packS s)
488sf_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)
485sf_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)
@@ -839,10 +836,7 @@ tests = [
839 testProperty "t_elemIndices" t_elemIndices,
836 testProperty "t_elemIndices" t_elemIndices,
840 testProperty "tl_elemIndices" tl_elemIndices,
837 testProperty "tl_elemIndices" tl_elemIndices,
841 testProperty "t_count" t_count,
838 testProperty "t_count" t_count,
842− testProperty "tl_count" tl_count,
839+ testProperty "tl_count" tl_count
843− testProperty "sf_countChar" sf_countChar,
844− testProperty "t_countChar" t_countChar,
845− testProperty "tl_countChar" tl_countChar
846 ],
840 ],
847
841
848 testGroup "zips" [
842 testGroup "zips" [