@@ -93,6 +93,7 @@ module Data.Text.Fusion
93 , findIndices
93 , findIndices
94 , findIndexOrEnd
94 , findIndexOrEnd
95 , elemIndex
95 , elemIndex
97 -- * Zipping and unzipping
98 -- * Zipping and unzipping
@@ -820,15 +821,23 @@ findIndexOrEnd p (Stream next s0 _len) = loop_findIndex 0 s0
820-- element in the given stream which is equal to the query
821-- element in the given stream which is equal to the query
821-- element, or 'Nothing' if there is no such element.
822-- element, or 'Nothing' if there is no such element.
822elemIndex :: Char -> Stream Char -> Maybe Int
823elemIndex :: Char -> Stream Char -> Maybe Int
823−elemIndex a (Stream next s0 _len) = loop_elemIndex 0 s0
824+elemIndex a s = case elemIndices a s of
824− where
825+ (i:_) -> Just i
825− loop_elemIndex !i !s = case next s of
826− Done -> Nothing
826+ _ -> Nothing
827− Skip s' -> loop_elemIndex i s'
828− Yield x s' | a == x -> Just i
829− | otherwise -> loop_elemIndex (i+1) s'
830{-# INLINE [0] elemIndex #-}
827{-# INLINE [0] elemIndex #-}
829+-- | /O(n)/ The 'elemIndices' function returns the index of every
830+-- element in the given stream which is equal to the query element.
831+elemIndices :: Char -> Stream Char -> [Int]
832+elemIndices a (Stream next s0 _len) = loop 0 s0
834+ loop !i !s = case next s of
836+ Skip s' -> loop i s'
837+ Yield x s' | a == x -> i : loop (i+1) s'
838+ | otherwise -> loop (i+1) s'
839+{-# INLINE [0] elemIndices #-}
832-------------------------------------------------------------------------------
841-------------------------------------------------------------------------------
833-- * Zipping
842-- * Zipping