@@ -657,29 +657,24 @@ fromPtr = Unfold step return
657657-- Specialized Generation
658658------------------------------------------------------------------------------
659659
660−-- XXX If the count depends on the input e.g. when we have to resample (see
661−-- resample in streamly-statistics) an array and we have to iterate as many
662−-- times as the array then we need the count to be passed via unfold i.e. it
663−-- should be Unfold m (Int, m a) a. We can use concatMap to pass the count
664−-- argument to replicateM but that won't perform well.
660+-- | Given a seed @(n, action)@, generates a stream replicating the @action@ @n@
661+-- times.
665662--
666−-- | Generates a stream replicating the seed @n@ times.
667−--
668−-- /Since: 0.8.0/
663+-- /Since: 0.9.0/
669664--
670665{-# INLINE replicateM #-}
671−replicateM :: Applicative m => Int -> Unfold m (m a) a
672−replicateM n = Unfold step inject
666+replicateM :: Applicative m => Unfold m (Int, m a) a
667+replicateM = Unfold step inject
673668
674669 where
675670
676− inject action = pure (action, n)
671+ inject seed = pure seed
677672
678673 {-# INLINE_LATE step #-}
679− step (action, i) =
674+ step (i, action) =
680675 if i <= 0
681676 then pure Stop
682− else (\x -> Yield x (action, i - 1)) <$> action
677+ else (\x -> Yield x (i - 1, action)) <$> action
683678
684679-- | Generates an infinite stream repeating the seed.
685680--