on master help sign in
Rename findBy back to find
15eaf1fBryan O'Sullivan
Data/Text.hs+14−14
@@ -150,8 +150,8 @@ module Data.Text
150
150
151 -- * Searching
151 -- * Searching
152 , filter
152 , filter
153+ , breakOnAll
153 , find
154 , find
154− , findBy
155 , partitionBy
155 , partitionBy
156
156
157 -- , findSubstring
157 -- , findSubstring
@@ -1136,12 +1136,12 @@ chunksOf k = go
1136-------------------------------------------------------------------------------
1136-------------------------------------------------------------------------------
1137-- ** Searching with a predicate
1137-- ** Searching with a predicate
1138
1138
1139−-- | /O(n)/ The 'findBy' function takes a predicate and a 'Text', and
1139+-- | /O(n)/ The 'find' function takes a predicate and a 'Text', and
1140−-- returns the first element in matching the predicate, or 'Nothing'
1140+-- returns the first element matching the predicate, or 'Nothing' if
1141−-- if there is no such element.
1141+-- there is no such element.
1142−findBy :: (Char -> Bool) -> Text -> Maybe Char
1142+find :: (Char -> Bool) -> Text -> Maybe Char
1143−findBy p t = S.findBy p (stream t)
1143+find p t = S.findBy p (stream t)
1144−{-# INLINE findBy #-}
1144+{-# INLINE find #-}
1145
1145
1146-- | /O(n)/ The 'partitionBy' function takes a predicate and a 'Text',
1146-- | /O(n)/ The 'partitionBy' function takes a predicate and a 'Text',
1147-- and returns the pair of 'Text's with elements which do and do not
1147-- and returns the pair of 'Text's with elements which do and do not
@@ -1175,7 +1175,7 @@ filter p t = unstream (S.filter p (stream t))
1175-- > where (prefix, match) = breakOn needle haystack
1175-- > where (prefix, match) = breakOn needle haystack
1176--
1176--
1177-- If you need to break a string by a substring repeatedly (e.g. you
1177-- If you need to break a string by a substring repeatedly (e.g. you
1178−-- want to break on every instance of a substring), use 'find'
1178+-- want to break on every instance of a substring), use 'breakOnAll'
1179-- instead, as it has lower startup overhead.
1179-- instead, as it has lower startup overhead.
1180--
1180--
1181-- In (unlikely) bad cases, this function's time complexity degrades
1181-- In (unlikely) bad cases, this function's time complexity degrades
@@ -1219,16 +1219,16 @@ breakOnEnd pat src = (reverse b, reverse a)
1219-- towards /O(n*m)/.
1219-- towards /O(n*m)/.
1220--
1220--
1221-- The @needle@ parameter may not be empty.
1221-- The @needle@ parameter may not be empty.
1222−find :: Text -- ^ @needle@ to search for
1222+breakOnAll :: Text -- ^ @needle@ to search for
1223− -> Text -- ^ @haystack@ in which to search
1223+ -> Text -- ^ @haystack@ in which to search
1224− -> [(Text, Text)]
1224+ -> [(Text, Text)]
1225−find pat src@(Text arr off slen)
1225+breakOnAll pat src@(Text arr off slen)
1226− | null pat = emptyError "find"
1226+ | null pat = emptyError "breakOnAll"
1227 | otherwise = L.map step (indices pat src)
1227 | otherwise = L.map step (indices pat src)
1228 where
1228 where
1229 step x = (chunk 0 x, chunk x (slen-x))
1229 step x = (chunk 0 x, chunk x (slen-x))
1230 chunk !n !l = textP arr (n+off) l
1230 chunk !n !l = textP arr (n+off) l
1231−{-# INLINE find #-}
1231+{-# INLINE breakOnAll #-}
1232
1232
1233-------------------------------------------------------------------------------
1233-------------------------------------------------------------------------------
1234-- ** Indexing 'Text's
1234-- ** Indexing 'Text's
Data/Text/Lazy.hs+12−12
@@ -156,7 +156,7 @@ module Data.Text.Lazy
156 -- * Searching
156 -- * Searching
157 , filter
157 , filter
158 , find
158 , find
159− , findBy
159+ , breakOnAll
160 , partitionBy
160 , partitionBy
161
161
162 -- , findSubstring
162 -- , findSubstring
@@ -1010,9 +1010,9 @@ breakOnEnd pat src = let (a,b) = breakOn (reverse pat) (reverse src)
1010--
1010--
1011-- Examples:
1011-- Examples:
1012--
1012--
1013−-- > find "::" ""
1013+-- > breakOnAll "::" ""
1014-- > ==> []
1014-- > ==> []
1015−-- > find "/" "a/b/c/"
1015+-- > breakOnAll "/" "a/b/c/"
1016-- > ==> [("a", "/b/c/"), ("a/b", "/c/"), ("a/b/c", "/")]
1016-- > ==> [("a", "/b/c/"), ("a/b", "/c/"), ("a/b/c", "/")]
1017--
1017--
1018-- This function is strict in its first argument, and lazy in its
1018-- This function is strict in its first argument, and lazy in its
@@ -1022,11 +1022,11 @@ breakOnEnd pat src = let (a,b) = breakOn (reverse pat) (reverse src)
1022-- towards /O(n*m)/.
1022-- towards /O(n*m)/.
1023--
1023--
1024-- The @needle@ parameter may not be empty.
1024-- The @needle@ parameter may not be empty.
1025−find :: Text -- ^ @needle@ to search for
1025+breakOnAll :: Text -- ^ @needle@ to search for
1026− -> Text -- ^ @haystack@ in which to search
1026+ -> Text -- ^ @haystack@ in which to search
1027− -> [(Text, Text)]
1027+ -> [(Text, Text)]
1028−find pat src
1028+breakOnAll pat src
1029− | null pat = emptyError "find"
1029+ | null pat = emptyError "breakOnAll"
1030 | otherwise = go 0 empty src (indices pat src)
1030 | otherwise = go 0 empty src (indices pat src)
1031 where
1031 where
1032 go !n p s (x:xs) = let h :*: t = splitAtWord (x-n) s
1032 go !n p s (x:xs) = let h :*: t = splitAtWord (x-n) s
@@ -1299,12 +1299,12 @@ filter :: (Char -> Bool) -> Text -> Text
1299filter p t = unstream (S.filter p (stream t))
1299filter p t = unstream (S.filter p (stream t))
1300{-# INLINE filter #-}
1300{-# INLINE filter #-}
1301
1301
1302−-- | /O(n)/ The 'findBy' function takes a predicate and a 'Text', and
1302+-- | /O(n)/ The 'find' function takes a predicate and a 'Text', and
1303-- returns the first element in matching the predicate, or 'Nothing'
1303-- returns the first element in matching the predicate, or 'Nothing'
1304-- if there is no such element.
1304-- if there is no such element.
1305−findBy :: (Char -> Bool) -> Text -> Maybe Char
1305+find :: (Char -> Bool) -> Text -> Maybe Char
1306−findBy p t = S.findBy p (stream t)
1306+find p t = S.findBy p (stream t)
1307−{-# INLINE findBy #-}
1307+{-# INLINE find #-}
1308
1308
1309-- | /O(n)/ The 'partitionBy' function takes a predicate and a 'Text',
1309-- | /O(n)/ The 'partitionBy' function takes a predicate and a 'Text',
1310-- and returns the pair of 'Text's with elements which do and do not
1310-- and returns the pair of 'Text's with elements which do and do not
tests/Properties.hs+10−10
@@ -511,17 +511,17 @@ t_tails = L.tails `eqP` (map unpackS . T.tails)
511tl_tails = L.tails `eqP` (map unpackS . TL.tails)
511tl_tails = L.tails `eqP` (map unpackS . TL.tails)
512t_findAppendId (NotEmpty s) = unsquare $ \ts ->
512t_findAppendId (NotEmpty s) = unsquare $ \ts ->
513 let t = T.intercalate s ts
513 let t = T.intercalate s ts
514− in all (==t) $ map (uncurry T.append) (T.find s t)
514+ in all (==t) $ map (uncurry T.append) (T.breakOnAll s t)
515tl_findAppendId (NotEmpty s) = unsquare $ \ts ->
515tl_findAppendId (NotEmpty s) = unsquare $ \ts ->
516 let t = TL.intercalate s ts
516 let t = TL.intercalate s ts
517− in all (==t) $ map (uncurry TL.append) (TL.find s t)
517+ in all (==t) $ map (uncurry TL.append) (TL.breakOnAll s t)
518−t_findContains (NotEmpty s) = all (T.isPrefixOf s . snd) . T.find s .
518+t_findContains (NotEmpty s) = all (T.isPrefixOf s . snd) . T.breakOnAll s .
519 T.intercalate s
519 T.intercalate s
520tl_findContains (NotEmpty s) = all (TL.isPrefixOf s . snd) .
520tl_findContains (NotEmpty s) = all (TL.isPrefixOf s . snd) .
521− TL.find s . TL.intercalate s
521+ TL.breakOnAll s . TL.intercalate s
522sl_filterCount c = (L.genericLength . L.filter (==c)) `eqP` SL.countChar c
522sl_filterCount c = (L.genericLength . L.filter (==c)) `eqP` SL.countChar c
523−t_findCount s = (L.length . T.find s) `eq` T.count s
523+t_findCount s = (L.length . T.breakOnAll s) `eq` T.count s
524−tl_findCount s = (L.genericLength . TL.find s) `eq` TL.count s
524+tl_findCount s = (L.genericLength . TL.breakOnAll s) `eq` TL.count s
525
525
526t_split_split s = (T.split s `eq` Slow.split s) . T.intercalate s
526t_split_split s = (T.split s `eq` Slow.split s) . T.intercalate s
527tl_split_split s = ((TL.split (TL.fromStrict s) . TL.fromStrict) `eq`
527tl_split_split s = ((TL.split (TL.fromStrict s) . TL.fromStrict) `eq`
@@ -597,8 +597,8 @@ sf_filter q p = (L.filter p . L.filter q) `eqP`
597t_filter p = L.filter p `eqP` (unpackS . T.filter p)
597t_filter p = L.filter p `eqP` (unpackS . T.filter p)
598tl_filter p = L.filter p `eqP` (unpackS . TL.filter p)
598tl_filter p = L.filter p `eqP` (unpackS . TL.filter p)
599sf_findBy q p = (L.find p . L.filter q) `eqP` (S.findBy p . S.filter q)
599sf_findBy q p = (L.find p . L.filter q) `eqP` (S.findBy p . S.filter q)
600−t_findBy p = L.find p `eqP` T.findBy p
600+t_find p = L.find p `eqP` T.find p
601−tl_findBy p = L.find p `eqP` TL.findBy p
601+tl_find p = L.find p `eqP` TL.find p
602t_partition p = L.partition p `eqP` (unpack2 . T.partitionBy p)
602t_partition p = L.partition p `eqP` (unpack2 . T.partitionBy p)
603tl_partition p = L.partition p `eqP` (unpack2 . TL.partitionBy p)
603tl_partition p = L.partition p `eqP` (unpack2 . TL.partitionBy p)
604
604
@@ -1130,8 +1130,8 @@ tests = [
1130 testProperty "t_filter" t_filter,
1130 testProperty "t_filter" t_filter,
1131 testProperty "tl_filter" tl_filter,
1131 testProperty "tl_filter" tl_filter,
1132 testProperty "sf_findBy" sf_findBy,
1132 testProperty "sf_findBy" sf_findBy,
1133− testProperty "t_findBy" t_findBy,
1133+ testProperty "t_find" t_find,
1134− testProperty "tl_findBy" tl_findBy,
1134+ testProperty "tl_find" tl_find,
1135 testProperty "t_partition" t_partition,
1135 testProperty "t_partition" t_partition,
1136 testProperty "tl_partition" tl_partition
1136 testProperty "tl_partition" tl_partition
1137 ],
1137 ],