Commits

Bryan O'Sullivan committed 083a7f9

Rename find to findBy, and findAll to find.

Comments (0)

Files changed (4)

 -- Laws:
 --
 -- > concat (prefix : matches) == haystack
--- >   where (prefix, matches) = findAll needle haystack
+-- >   where (prefix, matches) = find needle haystack
 find :: Text -> Text -> (Text, [Text])
 find pat@(Text _ _ plen) src@(Text sarr soff slen)
-    | plen <= 0 = emptyError "findAll"
+    | plen <= 0 = emptyError "find"
     | otherwise = (h,t)
   where
     (h:t)       = go 0 (search 0)

Data/Text/Fusion/Common.hs

     , filter
 
     -- * Indexing
-    , find
+    , findBy
     , indexI
     , findIndexI
     , findIndicesI
 -------------------------------------------------------------------------------
 -- ** Searching with a predicate
 
--- | /O(n)/ The 'find' function takes a predicate and a stream,
+-- | /O(n)/ The 'findBy' function takes a predicate and a stream,
 -- and returns the first element in matching the predicate, or 'Nothing'
 -- if there is no such element.
 
-find :: (Char -> Bool) -> Stream Char -> Maybe Char
-find p (Stream next s0 _len) = loop_find s0
+findBy :: (Char -> Bool) -> Stream Char -> Maybe Char
+findBy p (Stream next s0 _len) = loop_find s0
     where
       loop_find !s = case next s of
                        Done -> Nothing
                        Skip s' -> loop_find s'
                        Yield x s' | p x -> Just x
                                   | otherwise -> loop_find s'
-{-# INLINE [0] find #-}
+{-# INLINE [0] findBy #-}
 
 -- | /O(n)/ Stream index (subscript) operator, starting from 0.
 indexI :: Integral a => Stream Char -> a -> Char

Data/Text/Lazy.hs

     -- * Searching
     , elem
     , filter
-    , find
+    , findBy
     , partition
 
     -- , findSubstring
 filter p t = unstream (S.filter p (stream t))
 {-# INLINE filter #-}
 
--- | /O(n)/ The 'find' function takes a predicate and a 'Text',
--- and returns the first element in matching the predicate, or 'Nothing'
+-- | /O(n)/ The 'findBy' function takes a predicate and a 'Text', and
+-- returns the first element in matching the predicate, or 'Nothing'
 -- if there is no such element.
-find :: (Char -> Bool) -> Text -> Maybe Char
-find p t = S.find p (stream t)
-{-# INLINE find #-}
+findBy :: (Char -> Bool) -> Text -> Maybe Char
+findBy p t = S.findBy p (stream t)
+{-# INLINE findBy #-}
 
 -- | /O(n)/ The 'partition' function takes a predicate and a 'Text',
 -- and returns the pair of 'Text's with elements which do and do not

tests/Properties.hs

 sf_filter q p     = (L.filter p . L.filter q) `eqP` (unpackS . S.filter p . S.filter q)
 t_filter p        = L.filter p    `eqP` (unpackS . T.filter p)
 tl_filter p       = L.filter p    `eqP` (unpackS . TL.filter p)
-sf_find q p       = (L.find p . L.filter q) `eqP` (S.find p . S.filter q)
-t_find p          = L.find p      `eqP` T.find p
-tl_find p         = L.find p      `eqP` TL.find p
+sf_findBy q p     = (L.find p . L.filter q) `eqP` (S.findBy p . S.filter q)
+t_findBy p        = L.find p      `eqP` T.findBy p
+tl_findBy p       = L.find p      `eqP` TL.findBy p
 t_partition p     = L.partition p `eqP` (unpack2 . T.partition p)
 tl_partition p    = L.partition p `eqP` (unpack2 . TL.partition p)
 
     testProperty "sf_filter" sf_filter,
     testProperty "t_filter" t_filter,
     testProperty "tl_filter" tl_filter,
-    testProperty "sf_find" sf_find,
-    testProperty "t_find" t_find,
-    testProperty "tl_find" tl_find,
+    testProperty "sf_findBy" sf_findBy,
+    testProperty "t_findBy" t_findBy,
+    testProperty "tl_findBy" tl_findBy,
     testProperty "t_partition" t_partition,
     testProperty "tl_partition" tl_partition
   ],