on master help sign in
Rename span to spanBy, break to breakBy, and partition to partitionBy.
40ac812Bryan O'Sullivan
Data/Text.hs+22−22
@@ -114,8 +114,8 @@ module Data.Text
114 , stripStart
114 , stripStart
115 , stripEnd
115 , stripEnd
116 , splitAt
116 , splitAt
117− , span
117+ , spanBy
118− , break
118+ , breakBy
119 , group
119 , group
120 , groupBy
120 , groupBy
121 , inits
121 , inits
@@ -146,7 +146,7 @@ module Data.Text
146 , filter
146 , filter
147 , find
147 , find
148 , findBy
148 , findBy
149− , partition
149+ , partitionBy
150
150
151 -- , findSubstring
151 -- , findSubstring
152
152
@@ -841,23 +841,23 @@ splitAt n t@(Text arr off len)
841 where d = iter_ t i
841 where d = iter_ t i
842{-# INLINE splitAt #-}
842{-# INLINE splitAt #-}
843
843
844−-- | /O(n)/ 'span', applied to a predicate @p@ and text @t@, returns a
844+-- | /O(n)/ 'spanBy', applied to a predicate @p@ and text @t@, returns
845−-- pair whose first element is the longest prefix (possibly empty) of
845+-- a pair whose first element is the longest prefix (possibly empty)
846−-- @t@ of elements that satisfy @p@, and whose second is the remainder
846+-- of @t@ of elements that satisfy @p@, and whose second is the
847−-- of the list.
847+-- remainder of the list.
848−span :: (Char -> Bool) -> Text -> (Text, Text)
848+spanBy :: (Char -> Bool) -> Text -> (Text, Text)
849−span p t@(Text arr off len) = (textP arr off k, textP arr (off+k) (len-k))
849+spanBy p t@(Text arr off len) = (textP arr off k, textP arr (off+k) (len-k))
850 where k = loop 0
850 where k = loop 0
851 loop !i | i >= len || not (p c) = i
851 loop !i | i >= len || not (p c) = i
852 | otherwise = loop (i+d)
852 | otherwise = loop (i+d)
853 where (c,d) = iter t i
853 where (c,d) = iter t i
854−{-# INLINE span #-}
854+{-# INLINE spanBy #-}
855
855
856−-- | /O(n)/ 'break' is like 'span', but the prefix returned is over
856+-- | /O(n)/ 'breakBy' is like 'spanBy', but the prefix returned is
857−-- elements that fail the predicate @p@.
857+-- over elements that fail the predicate @p@.
858−break :: (Char -> Bool) -> Text -> (Text, Text)
858+breakBy :: (Char -> Bool) -> Text -> (Text, Text)
859−break p = span (not . p)
859+breakBy p = spanBy (not . p)
860−{-# INLINE break #-}
860+{-# INLINE breakBy #-}
861
861
862-- | /O(n)/ Group characters in a string according to a predicate.
862-- | /O(n)/ Group characters in a string according to a predicate.
863groupBy :: (Char -> Char -> Bool) -> Text -> [Text]
863groupBy :: (Char -> Char -> Bool) -> Text -> [Text]
@@ -997,7 +997,7 @@ splitBy _ t@(Text _off _arr 0) = [t]
997splitBy p t = loop t
997splitBy 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') = breakBy p s
1001{-# INLINE splitBy #-}
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
@@ -1035,14 +1035,14 @@ findBy :: (Char -> Bool) -> Text -> Maybe Char
1035findBy p t = S.findBy p (stream t)
1035findBy p t = S.findBy p (stream t)
1036{-# INLINE findBy #-}
1036{-# INLINE findBy #-}
1037
1037
1038−-- | /O(n)/ The 'partition' function takes a predicate and a 'Text',
1038+-- | /O(n)/ The 'partitionBy' function takes a predicate and a 'Text',
1039-- and returns the pair of 'Text's with elements which do and do not
1039-- and returns the pair of 'Text's with elements which do and do not
1040-- satisfy the predicate, respectively; i.e.
1040-- satisfy the predicate, respectively; i.e.
1041--
1041--
1042−-- > partition p t == (filter p t, filter (not . p) t)
1042+-- > partitionBy p t == (filter p t, filter (not . p) t)
1043−partition :: (Char -> Bool) -> Text -> (Text, Text)
1043+partitionBy :: (Char -> Bool) -> Text -> (Text, Text)
1044−partition p t = (filter p t, filter (not . p) t)
1044+partitionBy p t = (filter p t, filter (not . p) t)
1045−{-# INLINE partition #-}
1045+{-# INLINE partitionBy #-}
1046
1046
1047-- | /O(n)/ 'filter', applied to a predicate and a 'Text',
1047-- | /O(n)/ 'filter', applied to a predicate and a 'Text',
1048-- returns a 'Text' containing those characters that satisfy the
1048-- returns a 'Text' containing those characters that satisfy the
@@ -1179,7 +1179,7 @@ lines ps | null ps = []
1179 | otherwise = h : if null t
1179 | otherwise = h : if null t
1180 then []
1180 then []
1181 else lines (unsafeTail t)
1181 else lines (unsafeTail t)
1182− where (h,t) = span (/= '\n') ps
1182+ where (h,t) = spanBy (/= '\n') ps
1183{-# INLINE lines #-}
1183{-# INLINE lines #-}
1184
1184
1185-- | /O(n)/ Portably breaks a 'Text' up into a list of 'Text's at line
1185-- | /O(n)/ Portably breaks a 'Text' up into a list of 'Text's at line
Data/Text/Lazy.hs+20−20
@@ -118,8 +118,8 @@ module Data.Text.Lazy
118 , stripStart
118 , stripStart
119 , stripEnd
119 , stripEnd
120 , splitAt
120 , splitAt
121− , span
121+ , spanBy
122− , break
122+ , breakBy
123 , group
123 , group
124 , groupBy
124 , groupBy
125 , inits
125 , inits
@@ -149,7 +149,7 @@ module Data.Text.Lazy
149 , elem
149 , elem
150 , filter
150 , filter
151 , findBy
151 , findBy
152− , partition
152+ , partitionBy
153
153
154 -- , findSubstring
154 -- , findSubstring
155
155
@@ -804,10 +804,10 @@ splitAt = loop
804 in (Chunk t ts', ts'')
804 in (Chunk t ts', ts'')
805 where len = fromIntegral (T.length t)
805 where len = fromIntegral (T.length t)
806
806
807−-- | /O(n)/ 'break' is like 'span', but the prefix returned is over
807+-- | /O(n)/ 'breakBy' is like 'spanBy', but the prefix returned is over
808-- elements that fail the predicate @p@.
808-- elements that fail the predicate @p@.
809−break :: (Char -> Bool) -> Text -> (Text, Text)
809+breakBy :: (Char -> Bool) -> Text -> (Text, Text)
810−break p t0 = break' t0
810+breakBy p t0 = break' t0
811 where break' Empty = (empty, empty)
811 where break' Empty = (empty, empty)
812 break' c@(Chunk t ts) =
812 break' c@(Chunk t ts) =
813 case T.findIndex p t of
813 case T.findIndex p t of
@@ -817,13 +817,13 @@ break p t0 = break' t0
817 | otherwise -> let (a,b) = T.splitAt n t
817 | otherwise -> let (a,b) = T.splitAt n t
818 in (Chunk a Empty, Chunk b ts)
818 in (Chunk a Empty, Chunk b ts)
819
819
820−-- | /O(n)/ 'span', applied to a predicate @p@ and text @t@, returns a
820+-- | /O(n)/ 'spanBy', applied to a predicate @p@ and text @t@, returns
821−-- pair whose first element is the longest prefix (possibly empty) of
821+-- a pair whose first element is the longest prefix (possibly empty)
822−-- @t@ of elements that satisfy @p@, and whose second is the remainder
822+-- of @t@ of elements that satisfy @p@, and whose second is the
823−-- of the list.
823+-- remainder of the list.
824−span :: (Char -> Bool) -> Text -> (Text, Text)
824+spanBy :: (Char -> Bool) -> Text -> (Text, Text)
825−span p = break (not . p)
825+spanBy p = breakBy (not . p)
826−{-# INLINE span #-}
826+{-# INLINE spanBy #-}
827
827
828-- | The 'group' function takes a 'Text' and returns a list of 'Text's
828-- | The 'group' function takes a 'Text' and returns a list of 'Text's
829-- such that the concatenation of the result is equal to the argument.
829-- such that the concatenation of the result is equal to the argument.
@@ -842,7 +842,7 @@ group = groupBy (==)
842groupBy :: (Char -> Char -> Bool) -> Text -> [Text]
842groupBy :: (Char -> Char -> Bool) -> Text -> [Text]
843groupBy _ Empty = []
843groupBy _ Empty = []
844groupBy eq (Chunk t ts) = cons x ys : groupBy eq zs
844groupBy eq (Chunk t ts) = cons x ys : groupBy eq zs
845− where (ys,zs) = span (eq x) xs
845+ where (ys,zs) = spanBy (eq x) xs
846 x = T.unsafeHead t
846 x = T.unsafeHead t
847 xs = chunk (T.unsafeTail t) ts
847 xs = chunk (T.unsafeTail t) ts
848
848
@@ -989,7 +989,7 @@ chunksOf k = go
989-- newline 'Char's. The resulting strings do not contain newlines.
989-- newline 'Char's. The resulting strings do not contain newlines.
990lines :: Text -> [Text]
990lines :: Text -> [Text]
991lines Empty = []
991lines Empty = []
992−lines t = let (l,t') = break ((==) '\n') t
992+lines t = let (l,t') = breakBy ((==) '\n') t
993 in l : if null t' then []
993 in l : if null t' then []
994 else lines (tail t')
994 else lines (tail t')
995
995
@@ -1067,14 +1067,14 @@ findBy :: (Char -> Bool) -> Text -> Maybe Char
1067findBy p t = S.findBy p (stream t)
1067findBy p t = S.findBy p (stream t)
1068{-# INLINE findBy #-}
1068{-# INLINE findBy #-}
1069
1069
1070−-- | /O(n)/ The 'partition' function takes a predicate and a 'Text',
1070+-- | /O(n)/ The 'partitionBy' function takes a predicate and a 'Text',
1071-- and returns the pair of 'Text's with elements which do and do not
1071-- and returns the pair of 'Text's with elements which do and do not
1072-- satisfy the predicate, respectively; i.e.
1072-- satisfy the predicate, respectively; i.e.
1073--
1073--
1074−-- > partition p t == (filter p t, filter (not . p) t)
1074+-- > partitionBy p t == (filter p t, filter (not . p) t)
1075−partition :: (Char -> Bool) -> Text -> (Text, Text)
1075+partitionBy :: (Char -> Bool) -> Text -> (Text, Text)
1076−partition p t = (filter p t, filter (not . p) t)
1076+partitionBy p t = (filter p t, filter (not . p) t)
1077−{-# INLINE partition #-}
1077+{-# INLINE partitionBy #-}
1078
1078
1079-- | /O(n)/ 'Text' index (subscript) operator, starting from 0.
1079-- | /O(n)/ 'Text' index (subscript) operator, starting from 0.
1080index :: Text -> Int64 -> Char
1080index :: Text -> Int64 -> Char
tests/Properties.hs+6−6
@@ -385,10 +385,10 @@ t_strip = T.dropAround isSpace `eq` T.strip
385tl_strip = TL.dropAround isSpace `eq` TL.strip
385tl_strip = TL.dropAround isSpace `eq` TL.strip
386t_splitAt n = L.splitAt n `eqP` (unpack2 . T.splitAt n)
386t_splitAt n = L.splitAt n `eqP` (unpack2 . T.splitAt n)
387tl_splitAt n = L.splitAt n `eqP` (unpack2 . TL.splitAt (fromIntegral n))
387tl_splitAt n = L.splitAt n `eqP` (unpack2 . TL.splitAt (fromIntegral n))
388−t_span p = L.span p `eqP` (unpack2 . T.span p)
388+t_span p = L.span p `eqP` (unpack2 . T.spanBy p)
389−tl_span p = L.span p `eqP` (unpack2 . TL.span p)
389+tl_span p = L.span p `eqP` (unpack2 . TL.spanBy p)
390−t_break p = L.break p `eqP` (unpack2 . T.break p)
390+t_break p = L.break p `eqP` (unpack2 . T.breakBy p)
391−tl_break p = L.break p `eqP` (unpack2 . TL.break p)
391+tl_break p = L.break p `eqP` (unpack2 . TL.breakBy p)
392t_group = L.group `eqP` (map unpackS . T.group)
392t_group = L.group `eqP` (map unpackS . T.group)
393tl_group = L.group `eqP` (map unpackS . TL.group)
393tl_group = L.group `eqP` (map unpackS . TL.group)
394t_groupBy p = L.groupBy p `eqP` (map unpackS . T.groupBy p)
394t_groupBy p = L.groupBy p `eqP` (map unpackS . T.groupBy p)
@@ -481,8 +481,8 @@ tl_filter p = L.filter p `eqP` (unpackS . TL.filter p)
481sf_findBy q p = (L.find p . L.filter q) `eqP` (S.findBy p . S.filter q)
481sf_findBy q p = (L.find p . L.filter q) `eqP` (S.findBy p . S.filter q)
482t_findBy p = L.find p `eqP` T.findBy p
482t_findBy p = L.find p `eqP` T.findBy p
483tl_findBy p = L.find p `eqP` TL.findBy p
483tl_findBy p = L.find p `eqP` TL.findBy p
484−t_partition p = L.partition p `eqP` (unpack2 . T.partition p)
484+t_partition p = L.partition p `eqP` (unpack2 . T.partitionBy p)
485−tl_partition p = L.partition p `eqP` (unpack2 . TL.partition p)
485+tl_partition p = L.partition p `eqP` (unpack2 . TL.partitionBy p)
486
486
487sf_index p s = forAll (choose (-l,l*2)) ((L.filter p s L.!!) `eq` S.index (S.filter p $ packS s))
487sf_index p s = forAll (choose (-l,l*2)) ((L.filter p s L.!!) `eq` S.index (S.filter p $ packS s))
488 where l = L.length s
488 where l = L.length s