1. Bryan O'Sullivan
  2. text

Commits

Bryan O'Sullivan  committed dff9671

Get rid of most of findIndex, findIndices, elemIndex, and elemIndices.

  • Participants
  • Parent commits ec8b58b
  • Branches default

Comments (0)

Files changed (6)

File Data/Text.hs

View file
     -- $index
     , index
     , findIndex
-    , findIndices
-    , elemIndex
-    , elemIndices
     , count
 
     -- * Zipping and unzipping
 findIndex p t = S.findIndex p (stream t)
 {-# INLINE findIndex #-}
 
--- | The 'findIndices' function extends 'findIndex', by returning the
--- indices of all elements satisfying the predicate, in ascending
--- order. Subject to fusion.
-findIndices :: (Char -> Bool) -> Text -> [Int]
-findIndices p t = S.findIndices p (stream t)
-{-# INLINE findIndices #-}
-
--- | /O(n)/ The 'elemIndex' function returns the index of the first
--- element in the given 'Text' which is equal to the query element, or
--- 'Nothing' if there is no such element. Subject to fusion.
-elemIndex :: Char -> Text -> Maybe Int
-elemIndex c t = S.elemIndex c (stream t)
-{-# INLINE elemIndex #-}
-
--- | /O(n)/ The 'elemIndices' function returns the index of every
--- element in the given 'Text' which is equal to the query
--- element. Subject to fusion.
-elemIndices :: Char -> Text -> [Int]
-elemIndices c t = S.elemIndices c (stream t)
-{-# INLINE elemIndices #-}
-
 -- | /O(n+m)/ The 'count' function returns the number of times the
 -- query string appears in the given 'Text'. An empty query string is
 -- invalid, and will cause an error to be raised.

File Data/Text/Fusion.hs

View file
     -- * Indexing
     , index
     , findIndex
-    , findIndices
-    , findIndexOrEnd
-    , elemIndex
-    , elemIndices
     , countChar
     ) where
 
 findIndex = S.findIndexI
 {-# INLINE [0] findIndex #-}
 
--- | The 'findIndices' function takes a predicate and a stream and
--- returns all indices of the elements in the stream
--- satisfying the predicate.
-findIndices :: (Char -> Bool) -> Stream Char -> [Int]
-findIndices = S.findIndicesI
-{-# INLINE [0] findIndices #-}
-
--- | The 'findIndexOrEnd' function takes a predicate and a stream and
--- returns the index of the first element in the stream
--- satisfying the predicate.
-findIndexOrEnd :: (Char -> Bool) -> Stream Char -> Int
-findIndexOrEnd p (Stream next s0 _len) = loop_findIndex 0 s0
-  where
-    loop_findIndex !i !s = case next s of
-      Done                   -> i
-      Skip    s'             -> loop_findIndex i     s' -- hmm. not caught by QC
-      Yield x s' | p x       -> i
-                 | otherwise -> loop_findIndex (i+1) s'
-{-# INLINE [0] findIndexOrEnd #-}
-
--- | /O(n)/ The 'elemIndex' function returns the index of the first
--- element in the given stream which is equal to the query
--- element, or 'Nothing' if there is no such element.
-elemIndex :: Char -> Stream Char -> Maybe Int
-elemIndex = S.elemIndexI
-{-# INLINE [0] elemIndex #-}
-
--- | /O(n)/ The 'elemIndices' function returns the index of every
--- element in the given stream which is equal to the query element.
-elemIndices :: Char -> Stream Char -> [Int]
-elemIndices = S.elemIndicesI
-{-# INLINE [0] elemIndices #-}
-
 -- | /O(n)/ The 'count' function returns the number of times the query
 -- element appears in the given stream.
 countChar :: Char -> Stream Char -> Int

File Data/Text/Fusion/Common.hs

View file
     , findBy
     , indexI
     , findIndexI
-    , findIndicesI
-    , elemIndexI
-    , elemIndicesI
     , countCharI
 
     -- * Zipping and unzipping
                                     Yield b sb' -> Yield (f a b) (sa' :!: sb' :!: N)
 {-# INLINE [0] zipWith #-}
 
--- | /O(n)/ The 'elemIndexI' function returns the index of the first
--- element in the given stream which is equal to the query
--- element, or 'Nothing' if there is no such element.
-elemIndexI :: Integral a => Char -> Stream Char -> Maybe a
-elemIndexI a s = case elemIndicesI a s of
-                  (i:_) -> Just i
-                  _     -> Nothing
-{-# INLINE [0] elemIndexI #-}
-
--- | /O(n)/ The 'elemIndicesI' function returns the index of every
--- element in the given stream which is equal to the query element.
-elemIndicesI :: Integral a => Char -> Stream Char -> [a]
-elemIndicesI a (Stream next s0 _len) = loop 0 s0
-  where
-    loop !i !s = case next s of
-      Done                   -> []
-      Skip    s'             -> loop i s'
-      Yield x s' | a == x    -> i : loop (i+1) s'
-                 | otherwise -> loop (i+1) s'
-{-# INLINE [0] elemIndicesI #-}
-
 -- | /O(n)/ The 'countCharI' function returns the number of times the
 -- query element appears in the given stream.
 countCharI :: Integral a => Char -> Stream Char -> a

File Data/Text/Lazy.hs

View file
     
     -- * Indexing
     , index
-    , findIndex
-    , findIndices
-    , elemIndex
-    , elemIndices
     , count
 
     -- * Zipping and unzipping
 index t n = S.index (stream t) n
 {-# INLINE index #-}
 
--- | /O(n)/ The 'findIndex' function takes a predicate and a 'Text'
--- and returns the index of the first element in the 'Text' satisfying
--- the predicate. This function is subject to fusion.
-findIndex :: (Char -> Bool) -> Text -> Maybe Int64
-findIndex p t = S.findIndex p (stream t)
-{-# INLINE findIndex #-}
-
--- | The 'findIndices' function extends 'findIndex', by returning the
--- indices of all elements satisfying the predicate, in ascending
--- order. This function is subject to fusion.
-findIndices :: (Char -> Bool) -> Text -> [Int64]
-findIndices p t = S.findIndices p (stream t)
-{-# INLINE findIndices #-}
-
--- | /O(n)/ The 'elemIndex' function returns the index of the first
--- element in the given 'Text' which is equal to the query element, or
--- 'Nothing' if there is no such element. This function is subject to
--- fusion.
-elemIndex :: Char -> Text -> Maybe Int64
-elemIndex c t = S.elemIndex c (stream t)
-{-# INLINE elemIndex #-}
-
--- | /O(n)/ The 'elemIndices' function returns the index of every
--- element in the given 'Text' which is equal to the query
--- element. This function is subject to fusion.
-elemIndices :: Char -> Text -> [Int64]
-elemIndices c t = S.elemIndices c (stream t)
-{-# INLINE elemIndices #-}
-
 -- | /O(n*m)/ The 'count' function returns the number of times the
 -- query string appears in the given 'Text'. An empty query string is
 -- invalid, and will cause an error to be raised.

File Data/Text/Lazy/Fusion.hs

View file
     , length
     , unfoldrN
     , index
-    , findIndex
-    , findIndices
-    , elemIndex
-    , elemIndices
     , countChar
     ) where
 
 index = S.indexI
 {-# INLINE [0] index #-}
 
--- | The 'findIndex' function takes a predicate and a stream and
--- returns the index of the first element in the stream
--- satisfying the predicate.
-findIndex :: (Char -> Bool) -> Stream Char -> Maybe Int64
-findIndex = S.findIndexI
-{-# INLINE [0] findIndex #-}
-
--- | The 'findIndices' function takes a predicate and a stream and
--- returns all indices of the elements in the stream
--- satisfying the predicate.
-findIndices :: (Char -> Bool) -> Stream Char -> [Int64]
-findIndices = S.findIndicesI
-{-# INLINE [0] findIndices #-}
-
--- | /O(n)/ The 'elemIndex' function returns the index of the first
--- element in the given stream which is equal to the query
--- element, or 'Nothing' if there is no such element.
-elemIndex :: Char -> Stream Char -> Maybe Int64
-elemIndex = S.elemIndexI
-{-# INLINE [0] elemIndex #-}
-
--- | /O(n)/ The 'elemIndices' function returns the index of every
--- element in the given stream which is equal to the query element.
-elemIndices :: Char -> Stream Char -> [Int64]
-elemIndices = S.elemIndicesI
-{-# INLINE [0] elemIndices #-}
-
 -- | /O(n)/ The 'count' function returns the number of times the query
 -- element appears in the given stream.
 countChar :: Char -> Stream Char -> Int64

File tests/Properties.hs

View file
 tl_index s        = forAll (choose (-l,l*2)) ((s L.!!) `eq` (TL.index (packS s) . fromIntegral))
     where l = L.length s
 
-sf_findIndex q p  = (L.findIndex p . L.filter q) `eqP` (S.findIndex p . S.filter q)
 t_findIndex p     = L.findIndex p `eqP` T.findIndex p
-tl_findIndex p    = (fmap fromIntegral . L.findIndex p) `eqP` TL.findIndex p
-sf_findIndices q p= (L.findIndices p . L.filter q) `eqP` (S.findIndices p . S.filter q)
-t_findIndices p   = L.findIndices p `eqP` T.findIndices p
-tl_findIndices p  = (fmap fromIntegral . L.findIndices p) `eqP` TL.findIndices p
-sf_elemIndex p c  = (L.elemIndex c . L.filter p) `eqP` (S.elemIndex c . S.filter p)
-t_elemIndex c     = L.elemIndex c `eqP` T.elemIndex c
-tl_elemIndex c    = (fmap fromIntegral . L.elemIndex c) `eqP` TL.elemIndex c
-sf_elemIndices p c= (L.elemIndices c . L.filter p) `eqP` (S.elemIndices c . S.filter p)
-t_elemIndices c   = L.elemIndices c`eqP` T.elemIndices c
-tl_elemIndices c  = (fmap fromIntegral . L.elemIndices c) `eqP` TL.elemIndices c
 t_count t         = (subtract 1 . L.length . T.split t) `eq` T.count t
 tl_count t        = (subtract 1 . L.genericLength . TL.split t) `eq` TL.count t
 t_zip s           = L.zip s `eqP` T.zip (packS s)
     testProperty "sf_index" sf_index,
     testProperty "t_index" t_index,
     testProperty "tl_index" tl_index,
-    testProperty "sf_findIndex" sf_findIndex,
     testProperty "t_findIndex" t_findIndex,
-    testProperty "tl_findIndex" tl_findIndex,
-    testProperty "sf_findIndices" sf_findIndices,
-    testProperty "t_findIndices" t_findIndices,
-    testProperty "tl_findIndices" tl_findIndices,
-    testProperty "sf_elemIndex" sf_elemIndex,
-    testProperty "t_elemIndex" t_elemIndex,
-    testProperty "tl_elemIndex" tl_elemIndex,
-    testProperty "sf_elemIndices" sf_elemIndices,
-    testProperty "t_elemIndices" t_elemIndices,
-    testProperty "tl_elemIndices" tl_elemIndices,
     testProperty "t_count" t_count,
     testProperty "tl_count" tl_count,
     testProperty "t_indices" t_indices,