@@ -242,6 +242,8 @@ module Streamly.Internal.Data.MutArray.Type
242242
243243 -- *** Concat
244244 -- | Append the arrays in a stream to form a stream of elements.
245+ , concatWith
246+ , concatRevWith
245247 , concat
246248 , concatRev
247249
@@ -1653,16 +1655,10 @@ data FlattenState s contents a =
16531655 OuterLoop s
16541656 | InnerLoop s contents !Int !Int
16551657
1656−-- | Use the "reader" unfold instead.
1657−--
1658−-- @concat = unfoldMany reader@
1659−--
1660−-- We can try this if there are any fusion issues in the unfold.
1661−--
1662−{-# INLINE_NORMAL concat #-}
1663−concat :: forall m a. (MonadIO m, Unbox a)
1664− => D.Stream m (MutArray a) -> D.Stream m a
1665−concat (D.Stream step state) = D.Stream step' (OuterLoop state)
1658+{-# INLINE_NORMAL concatWith #-}
1659+concatWith :: forall m a. (Monad m, Unbox a)
1660+ => (forall b. IO b -> m b) -> D.Stream m (MutArray a) -> D.Stream m a
1661+concatWith liftio (D.Stream step state) = D.Stream step' (OuterLoop state)
16661662
16671663 where
16681664
@@ -1679,25 +1675,30 @@ concat (D.Stream step state) = D.Stream step' (OuterLoop state)
16791675 return $ D.Skip $ OuterLoop st
16801676
16811677 step' _ (InnerLoop st contents p end) = do
1682− x <- liftIO $ peekAt p contents
1678+ x <- liftio $ peekAt p contents
16831679 return $ D.Yield x (InnerLoop st contents (INDEX_NEXT(p,a)) end)
16841680
1681+-- | Use the "reader" unfold instead.
1682+--
1683+-- @concat = unfoldMany reader@
1684+--
1685+-- We can try this if there are any fusion issues in the unfold.
1686+--
1687+{-# INLINE_NORMAL concat #-}
1688+concat :: forall m a. (MonadIO m, Unbox a)
1689+ => D.Stream m (MutArray a) -> D.Stream m a
1690+concat = concatWith liftIO
1691+
16851692{-# DEPRECATED flattenArrays "Please use \"unfoldMany reader\" instead." #-}
16861693{-# INLINE flattenArrays #-}
16871694flattenArrays :: forall m a. (MonadIO m, Unbox a)
16881695 => D.Stream m (MutArray a) -> D.Stream m a
16891696flattenArrays = concat
16901697
1691−-- | Use the "readerRev" unfold instead.
1692−--
1693−-- @concat = unfoldMany readerRev@
1694−--
1695−-- We can try this if there are any fusion issues in the unfold.
1696−--
1697−{-# INLINE_NORMAL concatRev #-}
1698−concatRev :: forall m a. (MonadIO m, Unbox a)
1699− => D.Stream m (MutArray a) -> D.Stream m a
1700−concatRev (D.Stream step state) = D.Stream step' (OuterLoop state)
1698+{-# INLINE_NORMAL concatRevWith #-}
1699+concatRevWith :: forall m a. (Monad m, Unbox a)
1700+ => (forall b. IO b -> m b) -> D.Stream m (MutArray a) -> D.Stream m a
1701+concatRevWith liftio (D.Stream step state) = D.Stream step' (OuterLoop state)
17011702
17021703 where
17031704
@@ -1715,10 +1716,21 @@ concatRev (D.Stream step state) = D.Stream step' (OuterLoop state)
17151716 return $ D.Skip $ OuterLoop st
17161717
17171718 step' _ (InnerLoop st contents p start) = do
1718− x <- liftIO $ peekAt p contents
1719+ x <- liftio $ peekAt p contents
17191720 let cur = INDEX_PREV(p,a)
17201721 return $ D.Yield x (InnerLoop st contents cur start)
17211722
1723+-- | Use the "readerRev" unfold instead.
1724+--
1725+-- @concat = unfoldMany readerRev@
1726+--
1727+-- We can try this if there are any fusion issues in the unfold.
1728+--
1729+{-# INLINE_NORMAL concatRev #-}
1730+concatRev :: forall m a. (MonadIO m, Unbox a)
1731+ => D.Stream m (MutArray a) -> D.Stream m a
1732+concatRev = concatRevWith liftIO
1733+
17221734{-# DEPRECATED flattenArraysRev "Please use \"unfoldMany readerRev\" instead." #-}
17231735{-# INLINE flattenArraysRev #-}
17241736flattenArraysRev :: forall m a. (MonadIO m, Unbox a)