Fix replicateM in unfolds, don't perform action if not required.
commitc4f90b53ff1886d0df7928463cae0271c0cdd3bd
authoradithyaov <adithya@composewell.com>
dateTue 20 Oct 2020, 07:07 (6 years ago)
parentfdf02e7
src/Streamly/Internal/Data/Unfold.hs+6−6
@@ -503,12 +503,12 @@ replicateM n = Unfold step inject
503503 inject x = return (x, n)
504504
505505 {-# INLINE_LATE step #-}
506− step (x, i) = do
507− x1 <- x
508− return
509− $ if i <= 0
510− then Stop
511− else Yield x1 (x, i - 1)
506+ step (x, i) =
507+ if i <= 0
508+ then return Stop
509+ else do
510+ x1 <- x
511+ return $ Yield x1 (x, i - 1)
512512
513513-- | Generates an infinite stream repeating the seed.
514514--