on master help sign in
Rename splitWith to splitBy.
3ebc7faBryan O'Sullivan
Data/Text.hs+11−11
@@ -126,7 +126,7 @@ module Data.Text
126 , split
126 , split
127 , splitTimes
127 , splitTimes
128 , splitTimesEnd
128 , splitTimesEnd
129− , splitWith
129+ , splitBy
130 , chunksOf
130 , chunksOf
131
131
132 -- ** Breaking into lines and words
132 -- ** Breaking into lines and words
@@ -914,14 +914,14 @@ tails t | null t = [empty]
914-- and
914-- and
915--
915--
916-- > intercalate s . split s == id
916-- > intercalate s . split s == id
917−-- > split (singleton c) == splitWith (==c)
917+-- > split (singleton c) == splitBy (==c)
918--
918--
919-- In (unlikely) bad cases, this function's time complexity
919-- In (unlikely) bad cases, this function's time complexity
920-- degenerates towards /O(n*m)/.
920-- degenerates towards /O(n*m)/.
921split :: Text -> Text -> [Text]
921split :: Text -> Text -> [Text]
922split pat@(Text _ _ l) src@(Text arr off len)
922split pat@(Text _ _ l) src@(Text arr off len)
923 | l <= 0 = emptyError "split"
923 | l <= 0 = emptyError "split"
924− | isSingleton pat = splitWith (== unsafeHead pat) src
924+ | isSingleton pat = splitBy (== unsafeHead pat) src
925 | otherwise = go 0 (indices pat src)
925 | otherwise = go 0 (indices pat src)
926 where
926 where
927 go !s (x:xs) = textP arr (s+off) (x-s) : go (x+l) xs
927 go !s (x:xs) = textP arr (s+off) (x-s) : go (x+l) xs
@@ -929,8 +929,8 @@ split pat@(Text _ _ l) src@(Text arr off len)
929{-# INLINE [1] split #-}
929{-# INLINE [1] split #-}
930
930
931{-# RULES
931{-# RULES
932−"TEXT split/singleton -> splitWith/==" [~1] forall c t.
932+"TEXT split/singleton -> splitBy/==" [~1] forall c t.
933− split (singleton c) t = splitWith (==c) t
933+ split (singleton c) t = splitBy (==c) t
934 #-}
934 #-}
935
935
936-- | /O(m+n)/ Break a 'Text' into pieces at most @k@ times,
936-- | /O(m+n)/ Break a 'Text' into pieces at most @k@ times,
@@ -990,15 +990,15 @@ splitTimesEnd k pat src =
990-- resulting components do not contain the separators. Two adjacent
990-- resulting components do not contain the separators. Two adjacent
991-- separators result in an empty component in the output. eg.
991-- separators result in an empty component in the output. eg.
992--
992--
993−-- > splitWith (=='a') "aabbaca" == ["","","bb","c",""]
993+-- > splitBy (=='a') "aabbaca" == ["","","bb","c",""]
994−-- > splitWith (=='a') "" == [""]
994+-- > splitBy (=='a') "" == [""]
995−splitWith :: (Char -> Bool) -> Text -> [Text]
995+splitBy :: (Char -> Bool) -> Text -> [Text]
996−splitWith _ t@(Text _off _arr 0) = [t]
996+splitBy _ t@(Text _off _arr 0) = [t]
997−splitWith p t = loop t
997+splitBy p t = loop t
998 where loop s | null s' = [l]
998 where loop s | null s' = [l]
999 | otherwise = l : loop (unsafeTail s')
999 | otherwise = l : loop (unsafeTail s')
1000 where (l, s') = break p s
1000 where (l, s') = break p s
1001−{-# INLINE splitWith #-}
1001+{-# INLINE splitBy #-}
1002
1002
1003-- | /O(n)/ Splits a 'Text' into components of length @k@. The last
1003-- | /O(n)/ Splits a 'Text' into components of length @k@. The last
1004-- element may be shorter than the other chunks, depending on the
1004-- element may be shorter than the other chunks, depending on the
Data/Text/Lazy.hs+14−14
@@ -130,7 +130,7 @@ module Data.Text.Lazy
130 , split
130 , split
131 , splitTimes
131 , splitTimes
132 , splitTimesEnd
132 , splitTimesEnd
133− , splitWith
133+ , splitBy
134 , chunksOf
134 , chunksOf
135 -- , breakSubstring
135 -- , breakSubstring
136
136
@@ -881,13 +881,13 @@ tails ts@(Chunk t ts')
881-- and
881-- and
882--
882--
883-- > intercalate s . split s == id
883-- > intercalate s . split s == id
884−-- > split (singleton c) == splitWith (==c)
884+-- > split (singleton c) == splitBy (==c)
885split :: Text -- ^ Text to split on
885split :: Text -- ^ Text to split on
886 -> Text -- ^ Input text
886 -> Text -- ^ Input text
887 -> [Text]
887 -> [Text]
888split pat src0
888split pat src0
889 | l == 0 = emptyError "split"
889 | l == 0 = emptyError "split"
890− | l == 1 = splitWith (== (head pat)) src0
890+ | l == 1 = splitBy (== (head pat)) src0
891 | otherwise = go src0
891 | otherwise = go src0
892 where
892 where
893 l = length pat
893 l = length pat
@@ -900,8 +900,8 @@ split pat src0
900{-# INLINE [1] split #-}
900{-# INLINE [1] split #-}
901
901
902{-# RULES
902{-# RULES
903−"LAZY TEXT split/singleton -> splitWith/==" [~1] forall c t.
903+"LAZY TEXT split/singleton -> splitBy/==" [~1] forall c t.
904− split (singleton c) t = splitWith (==c) t
904+ split (singleton c) t = splitBy (==c) t
905 #-}
905 #-}
906
906
907-- | /O(m)*O(n)/ Break a 'Text' into pieces at most @k@ times,
907-- | /O(m)*O(n)/ Break a 'Text' into pieces at most @k@ times,
@@ -960,16 +960,16 @@ splitTimesEnd k pat src =
960-- resulting components do not contain the separators. Two adjacent
960-- resulting components do not contain the separators. Two adjacent
961-- separators result in an empty component in the output. eg.
961-- separators result in an empty component in the output. eg.
962--
962--
963−-- > splitWith (=='a') "aabbaca" == ["","","bb","c",""]
963+-- > splitBy (=='a') "aabbaca" == ["","","bb","c",""]
964−-- > splitWith (=='a') [] == [""]
964+-- > splitBy (=='a') [] == [""]
965−splitWith :: (Char -> Bool) -> Text -> [Text]
965+splitBy :: (Char -> Bool) -> Text -> [Text]
966−splitWith _ Empty = [Empty]
966+splitBy _ Empty = [Empty]
967−splitWith p (Chunk t0 ts0) = comb [] (T.splitWith p t0) ts0
967+splitBy p (Chunk t0 ts0) = comb [] (T.splitBy p t0) ts0
968 where comb acc (s:[]) Empty = revChunks (s:acc) : []
968 where comb acc (s:[]) Empty = revChunks (s:acc) : []
969− comb acc (s:[]) (Chunk t ts) = comb (s:acc) (T.splitWith p t) ts
969+ comb acc (s:[]) (Chunk t ts) = comb (s:acc) (T.splitBy p t) ts
970 comb acc (s:ss) ts = revChunks (s:acc) : comb [] ss ts
970 comb acc (s:ss) ts = revChunks (s:acc) : comb [] ss ts
971− comb _ [] _ = impossibleError "splitWith"
971+ comb _ [] _ = impossibleError "splitBy"
972−{-# INLINE splitWith #-}
972+{-# INLINE splitBy #-}
973
973
974-- | /O(n)/ Splits a 'Text' into components of length @k@. The last
974-- | /O(n)/ Splits a 'Text' into components of length @k@. The last
975-- element may be shorter than the other chunks, depending on the
975-- element may be shorter than the other chunks, depending on the
@@ -996,7 +996,7 @@ lines t = let (l,t') = break ((==) '\n') t
996-- | /O(n)/ Breaks a 'Text' up into a list of words, delimited by 'Char's
996-- | /O(n)/ Breaks a 'Text' up into a list of words, delimited by 'Char's
997-- representing white space.
997-- representing white space.
998words :: Text -> [Text]
998words :: Text -> [Text]
999−words = L.filter (not . null) . splitWith isSpace
999+words = L.filter (not . null) . splitBy isSpace
1000{-# INLINE words #-}
1000{-# INLINE words #-}
1001
1001
1002-- | /O(n)/ Joins lines, after appending a terminating newline to
1002-- | /O(n)/ Joins lines, after appending a terminating newline to
tests/Properties.hs+12−12
@@ -422,14 +422,14 @@ tl_splitTimesEnd_i k (NotEmpty t) = id `eq` (TL.intercalate t . TL.splitTimesEnd
422t_splitTimesEnd_split (NotEmpty t) = T.splitTimesEnd maxBound t `eq` T.split t
422t_splitTimesEnd_split (NotEmpty t) = T.splitTimesEnd maxBound t `eq` T.split t
423tl_splitTimesEnd_split (NotEmpty t) = TL.splitTimesEnd maxBound t `eq` TL.split t
423tl_splitTimesEnd_split (NotEmpty t) = TL.splitTimesEnd maxBound t `eq` TL.split t
424
424
425−t_splitWith p = splitWith p `eqP` (map unpackS . T.splitWith p)
425+t_splitBy p = splitBy p `eqP` (map unpackS . T.splitBy p)
426−t_splitWith_count c = (L.length . T.splitWith (==c)) `eq` ((1+) . T.count (T.singleton c))
426+t_splitBy_count c = (L.length . T.splitBy (==c)) `eq` ((1+) . T.count (T.singleton c))
427−t_splitWith_split c = T.splitWith (==c) `eq` T.split (T.singleton c)
427+t_splitBy_split c = T.splitBy (==c) `eq` T.split (T.singleton c)
428−tl_splitWith p = splitWith p `eqP` (map unpackS . TL.splitWith p)
428+tl_splitBy p = splitBy p `eqP` (map unpackS . TL.splitBy p)
429−
429+
430−splitWith :: (a -> Bool) -> [a] -> [[a]]
430+splitBy :: (a -> Bool) -> [a] -> [[a]]
431−splitWith _ [] = [[]]
431+splitBy _ [] = [[]]
432−splitWith p xs = loop xs
432+splitBy p xs = loop xs
433 where loop s | null s' = [l]
433 where loop s | null s' = [l]
434 | otherwise = l : loop (tail s')
434 | otherwise = l : loop (tail s')
435 where (l, s') = break p s
435 where (l, s') = break p s
@@ -807,10 +807,10 @@ tests = [
807 testProperty "t_splitTimesEnd_split" t_splitTimesEnd_split,
807 testProperty "t_splitTimesEnd_split" t_splitTimesEnd_split,
808 testProperty "tl_splitTimesEnd_split" tl_splitTimesEnd_split,
808 testProperty "tl_splitTimesEnd_split" tl_splitTimesEnd_split,
809 testProperty "tl_split_i" tl_split_i,
809 testProperty "tl_split_i" tl_split_i,
810− testProperty "t_splitWith" t_splitWith,
810+ testProperty "t_splitBy" t_splitBy,
811− testProperty "t_splitWith_count" t_splitWith_count,
811+ testProperty "t_splitBy_count" t_splitBy_count,
812− testProperty "t_splitWith_split" t_splitWith_split,
812+ testProperty "t_splitBy_split" t_splitBy_split,
813− testProperty "tl_splitWith" tl_splitWith,
813+ testProperty "tl_splitBy" tl_splitBy,
814 testProperty "t_chunksOf_same_lengths" t_chunksOf_same_lengths,
814 testProperty "t_chunksOf_same_lengths" t_chunksOf_same_lengths,
815 testProperty "t_chunksOf_length" t_chunksOf_length,
815 testProperty "t_chunksOf_length" t_chunksOf_length,
816 testProperty "tl_chunksOf" tl_chunksOf
816 testProperty "tl_chunksOf" tl_chunksOf
tests/SlowFunctions.hs+1−1
@@ -28,7 +28,7 @@ split :: Text -- ^ Text to split on
28 -> [Text]
28 -> [Text]
29split pat src0
29split pat src0
30 | T.null pat = error "split: empty"
30 | T.null pat = error "split: empty"
31− | l == 1 = T.splitWith (== (unsafeHead pat)) src0
31+ | l == 1 = T.splitBy (== (unsafeHead pat)) src0
32 | otherwise = go src0
32 | otherwise = go src0
33 where
33 where
34 l = T.length pat
34 l = T.length pat