@@ -128,9 +128,9 @@ module Streamly.Internal.Data.Fold
128128 , mapMaybe
129129 -- , mapMaybeM
130130
131− {-
132131 -- ** Scanning Filters
133132 , findIndices
133+ {-
134134 , elemIndices
135135
136136 -- ** Insertion
@@ -893,6 +893,23 @@ findIndex predicate = mkFold step (Partial 0) (const Nothing)
893893 then Done $ Just i
894894 else Partial (i + 1)
895895
896+-- XXX If we have a Continue contructor we won't need a Maybe type for the
897+-- scan. The fold will have the ability to skip producing output.
898+--
899+-- | Returns all indices that satisfy the given predicate.
900+--
901+{-# INLINE findIndices #-}
902+findIndices :: Monad m => (a -> Bool) -> Fold m a (Maybe Int)
903+findIndices predicate =
904+ fmap (either (const Nothing) Just) $ foldl' step (Left (-1))
905+
906+ where
907+
908+ step i a =
909+ if predicate a
910+ then Right (either id id i + 1)
911+ else Left (either id id i + 1)
912+
896913-- | Returns the first index where a given value is found in the stream.
897914--
898915-- > elemIndex a = Fold.findIndex (== a)