@@ -93,6 +93,7 @@ module Data.Text.Fusion
9393 , findIndices
9494 , findIndexOrEnd
9595 , elemIndex
96+ , elemIndices
9697
9798 -- * Zipping and unzipping
9899 , zipWith
@@ -820,15 +821,23 @@ findIndexOrEnd p (Stream next s0 _len) = loop_findIndex 0 s0
820821-- element in the given stream which is equal to the query
821822-- element, or 'Nothing' if there is no such element.
822823elemIndex :: Char -> Stream Char -> Maybe Int
823−elemIndex a (Stream next s0 _len) = loop_elemIndex 0 s0
824− where
825− loop_elemIndex !i !s = case next s of
826− Done -> Nothing
827− Skip s' -> loop_elemIndex i s'
828− Yield x s' | a == x -> Just i
829− | otherwise -> loop_elemIndex (i+1) s'
824+elemIndex a s = case elemIndices a s of
825+ (i:_) -> Just i
826+ _ -> Nothing
830827{-# INLINE [0] elemIndex #-}
831828
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
833+ where
834+ loop !i !s = case next s of
835+ Done -> []
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 #-}
840+
832841-------------------------------------------------------------------------------
833842-- * Zipping
834843