on master help sign in
Rename span to spanBy, break to breakBy, and partition to partitionBy.

--HG-- extra : convert_revision : 248c43f35c5b25fc33e6c3ec159825709a38844f

commit40ac8127302e9c4173edc415ec863719f7931410 authorBryan O'Sullivan <bos@serpentine.com> dateTue 6 Oct 2009, 20:47 (17 years ago) parent3ebc7fa
3 files changed+48−48
Data/Text.hs+22−22 Data/Text/Lazy.hs+20−20 tests/Properties.hs+6−6
Data/Text.hs+22−22
@@ -114,8 +114,8 @@ module Data.Text
114114 , stripStart
115115 , stripEnd
116116 , splitAt
117− , span
118− , break
117+ , spanBy
118+ , breakBy
119119 , group
120120 , groupBy
121121 , inits
@@ -146,7 +146,7 @@ module Data.Text
146146 , filter
147147 , find
148148 , findBy
149− , partition
149+ , partitionBy
150150
151151 -- , findSubstring
152152
@@ -841,23 +841,23 @@ splitAt n t@(Text arr off len)
841841 where d = iter_ t i
842842{-# INLINE splitAt #-}
843843
844−-- | /O(n)/ 'span', applied to a predicate @p@ and text @t@, returns a
845−-- pair whose first element is the longest prefix (possibly empty) of
846−-- @t@ of elements that satisfy @p@, and whose second is the remainder
847−-- of the list.
848−span :: (Char -> Bool) -> Text -> (Text, Text)
849−span p t@(Text arr off len) = (textP arr off k, textP arr (off+k) (len-k))
844+-- | /O(n)/ 'spanBy', applied to a predicate @p@ and text @t@, returns
845+-- a pair whose first element is the longest prefix (possibly empty)
846+-- of @t@ of elements that satisfy @p@, and whose second is the
847+-- remainder of the list.
848+spanBy :: (Char -> Bool) -> Text -> (Text, Text)
849+spanBy p t@(Text arr off len) = (textP arr off k, textP arr (off+k) (len-k))
850850 where k = loop 0
851851 loop !i | i >= len || not (p c) = i
852852 | otherwise = loop (i+d)
853853 where (c,d) = iter t i
854−{-# INLINE span #-}
854+{-# INLINE spanBy #-}
855855
856−-- | /O(n)/ 'break' is like 'span', but the prefix returned is over
857−-- elements that fail the predicate @p@.
858−break :: (Char -> Bool) -> Text -> (Text, Text)
859−break p = span (not . p)
860−{-# INLINE break #-}
856+-- | /O(n)/ 'breakBy' is like 'spanBy', but the prefix returned is
857+-- over elements that fail the predicate @p@.
858+breakBy :: (Char -> Bool) -> Text -> (Text, Text)
859+breakBy p = spanBy (not . p)
860+{-# INLINE breakBy #-}
861861
862862-- | /O(n)/ Group characters in a string according to a predicate.
863863groupBy :: (Char -> Char -> Bool) -> Text -> [Text]
@@ -997,7 +997,7 @@ splitBy _ t@(Text _off _arr 0) = [t]
997997splitBy p t = loop t
998998 where loop s | null s' = [l]
999999 | otherwise = l : loop (unsafeTail s')
1000− where (l, s') = break p s
1000+ where (l, s') = breakBy p s
10011001{-# INLINE splitBy #-}
10021002
10031003-- | /O(n)/ Splits a 'Text' into components of length @k@. The last
@@ -1035,14 +1035,14 @@ findBy :: (Char -> Bool) -> Text -> Maybe Char
10351035findBy p t = S.findBy p (stream t)
10361036{-# INLINE findBy #-}
10371037
1038−-- | /O(n)/ The 'partition' function takes a predicate and a 'Text',
1038+-- | /O(n)/ The 'partitionBy' function takes a predicate and a 'Text',
10391039-- and returns the pair of 'Text's with elements which do and do not
10401040-- satisfy the predicate, respectively; i.e.
10411041--
1042−-- > partition p t == (filter p t, filter (not . p) t)
1043−partition :: (Char -> Bool) -> Text -> (Text, Text)
1044−partition p t = (filter p t, filter (not . p) t)
1045−{-# INLINE partition #-}
1042+-- > partitionBy p t == (filter p t, filter (not . p) t)
1043+partitionBy :: (Char -> Bool) -> Text -> (Text, Text)
1044+partitionBy p t = (filter p t, filter (not . p) t)
1045+{-# INLINE partitionBy #-}
10461046
10471047-- | /O(n)/ 'filter', applied to a predicate and a 'Text',
10481048-- returns a 'Text' containing those characters that satisfy the
@@ -1179,7 +1179,7 @@ lines ps | null ps = []
11791179 | otherwise = h : if null t
11801180 then []
11811181 else lines (unsafeTail t)
1182− where (h,t) = span (/= '\n') ps
1182+ where (h,t) = spanBy (/= '\n') ps
11831183{-# INLINE lines #-}
11841184
11851185-- | /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
118118 , stripStart
119119 , stripEnd
120120 , splitAt
121− , span
122− , break
121+ , spanBy
122+ , breakBy
123123 , group
124124 , groupBy
125125 , inits
@@ -149,7 +149,7 @@ module Data.Text.Lazy
149149 , elem
150150 , filter
151151 , findBy
152− , partition
152+ , partitionBy
153153
154154 -- , findSubstring
155155
@@ -804,10 +804,10 @@ splitAt = loop
804804 in (Chunk t ts', ts'')
805805 where len = fromIntegral (T.length t)
806806
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
808808-- elements that fail the predicate @p@.
809−break :: (Char -> Bool) -> Text -> (Text, Text)
810−break p t0 = break' t0
809+breakBy :: (Char -> Bool) -> Text -> (Text, Text)
810+breakBy p t0 = break' t0
811811 where break' Empty = (empty, empty)
812812 break' c@(Chunk t ts) =
813813 case T.findIndex p t of
@@ -817,13 +817,13 @@ break p t0 = break' t0
817817 | otherwise -> let (a,b) = T.splitAt n t
818818 in (Chunk a Empty, Chunk b ts)
819819
820−-- | /O(n)/ 'span', applied to a predicate @p@ and text @t@, returns a
821−-- pair whose first element is the longest prefix (possibly empty) of
822−-- @t@ of elements that satisfy @p@, and whose second is the remainder
823−-- of the list.
824−span :: (Char -> Bool) -> Text -> (Text, Text)
825−span p = break (not . p)
826−{-# INLINE span #-}
820+-- | /O(n)/ 'spanBy', applied to a predicate @p@ and text @t@, returns
821+-- a pair whose first element is the longest prefix (possibly empty)
822+-- of @t@ of elements that satisfy @p@, and whose second is the
823+-- remainder of the list.
824+spanBy :: (Char -> Bool) -> Text -> (Text, Text)
825+spanBy p = breakBy (not . p)
826+{-# INLINE spanBy #-}
827827
828828-- | The 'group' function takes a 'Text' and returns a list of 'Text's
829829-- such that the concatenation of the result is equal to the argument.
@@ -842,7 +842,7 @@ group = groupBy (==)
842842groupBy :: (Char -> Char -> Bool) -> Text -> [Text]
843843groupBy _ Empty = []
844844groupBy 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
846846 x = T.unsafeHead t
847847 xs = chunk (T.unsafeTail t) ts
848848
@@ -989,7 +989,7 @@ chunksOf k = go
989989-- newline 'Char's. The resulting strings do not contain newlines.
990990lines :: Text -> [Text]
991991lines Empty = []
992−lines t = let (l,t') = break ((==) '\n') t
992+lines t = let (l,t') = breakBy ((==) '\n') t
993993 in l : if null t' then []
994994 else lines (tail t')
995995
@@ -1067,14 +1067,14 @@ findBy :: (Char -> Bool) -> Text -> Maybe Char
10671067findBy p t = S.findBy p (stream t)
10681068{-# INLINE findBy #-}
10691069
1070−-- | /O(n)/ The 'partition' function takes a predicate and a 'Text',
1070+-- | /O(n)/ The 'partitionBy' function takes a predicate and a 'Text',
10711071-- and returns the pair of 'Text's with elements which do and do not
10721072-- satisfy the predicate, respectively; i.e.
10731073--
1074−-- > partition p t == (filter p t, filter (not . p) t)
1075−partition :: (Char -> Bool) -> Text -> (Text, Text)
1076−partition p t = (filter p t, filter (not . p) t)
1077−{-# INLINE partition #-}
1074+-- > partitionBy p t == (filter p t, filter (not . p) t)
1075+partitionBy :: (Char -> Bool) -> Text -> (Text, Text)
1076+partitionBy p t = (filter p t, filter (not . p) t)
1077+{-# INLINE partitionBy #-}
10781078
10791079-- | /O(n)/ 'Text' index (subscript) operator, starting from 0.
10801080index :: Text -> Int64 -> Char
tests/Properties.hs+6−6
@@ -385,10 +385,10 @@ t_strip = T.dropAround isSpace `eq` T.strip
385385tl_strip = TL.dropAround isSpace `eq` TL.strip
386386t_splitAt n = L.splitAt n `eqP` (unpack2 . T.splitAt n)
387387tl_splitAt n = L.splitAt n `eqP` (unpack2 . TL.splitAt (fromIntegral n))
388−t_span p = L.span p `eqP` (unpack2 . T.span p)
389−tl_span p = L.span p `eqP` (unpack2 . TL.span p)
390−t_break p = L.break p `eqP` (unpack2 . T.break p)
391−tl_break p = L.break p `eqP` (unpack2 . TL.break p)
388+t_span p = L.span p `eqP` (unpack2 . T.spanBy p)
389+tl_span p = L.span p `eqP` (unpack2 . TL.spanBy p)
390+t_break p = L.break p `eqP` (unpack2 . T.breakBy p)
391+tl_break p = L.break p `eqP` (unpack2 . TL.breakBy p)
392392t_group = L.group `eqP` (map unpackS . T.group)
393393tl_group = L.group `eqP` (map unpackS . TL.group)
394394t_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)
481481sf_findBy q p = (L.find p . L.filter q) `eqP` (S.findBy p . S.filter q)
482482t_findBy p = L.find p `eqP` T.findBy p
483483tl_findBy p = L.find p `eqP` TL.findBy p
484−t_partition p = L.partition p `eqP` (unpack2 . T.partition p)
485−tl_partition p = L.partition p `eqP` (unpack2 . TL.partition p)
484+t_partition p = L.partition p `eqP` (unpack2 . T.partitionBy p)
485+tl_partition p = L.partition p `eqP` (unpack2 . TL.partitionBy p)
486486
487487sf_index p s = forAll (choose (-l,l*2)) ((L.filter p s L.!!) `eq` S.index (S.filter p $ packS s))
488488 where l = L.length s