on master help sign in
Expose postscanl' and postscanlM'
3ae0b40Harendra Kumar
Changelog.md+1
@@ -63,6 +63,7 @@ example, concat streams concurrently using this.
63* Add the following to `Streamly.Prelude`:
63* Add the following to `Streamly.Prelude`:
64 * `foldrS` to fold a stream to a stream
64 * `foldrS` to fold a stream to a stream
65 * `foldrT` to fold a stream to an arbitrary transformer monad
65 * `foldrT` to fold a stream to an arbitrary transformer monad
66+ * `postscanl'` and `postscanlM'`
66 * `reverse'` a several times faster reverse using Storable instance
67 * `reverse'` a several times faster reverse using Storable instance
67 * `intersperseByTime` intersperse a mondadic action in a stream
68 * `intersperseByTime` intersperse a mondadic action in a stream
68 periodically
69 periodically
src/Streamly/Prelude.hs+13−14
@@ -313,8 +313,8 @@ module Streamly.Prelude
313
313
314 , scanl'
314 , scanl'
315 , scanlM'
315 , scanlM'
316− -- , postscanl'
316+ , postscanl'
317− -- , postscanlM'
317+ , postscanlM'
318 -- , prescanl'
318 -- , prescanl'
319 -- , prescanlM'
319 -- , prescanlM'
320 , scanl1'
320 , scanl1'
@@ -1659,23 +1659,22 @@ scanlM' step begin m = fromStreamD $ D.scanlM' step begin $ toStreamD m
1659scanl' :: (IsStream t, Monad m) => (b -> a -> b) -> b -> t m a -> t m b
1659scanl' :: (IsStream t, Monad m) => (b -> a -> b) -> b -> t m a -> t m b
1660scanl' step z m = fromStreamS $ S.scanl' step z $ toStreamS m
1660scanl' step z m = fromStreamS $ S.scanl' step z $ toStreamS m
1661
1661
1662−-- XXX enable once the signature (monadic zero) change is settled
1663−-- | Like scanl' but does not stream the initial value of the accumulator.
1662+-- | Like 'scanl'' but does not stream the initial value of the accumulator.
1664--
1663--
1665−-- > postscanl' f z xs = S.drop 1 $ scanl' f z xs
1664+-- > postscanl' f z xs = S.drop 1 $ S.scanl' f z xs
1666--
1665--
1667−-- @since 0.6.0
1666+-- @since 0.7.0
1668−{-# INLINE _postscanl' #-}
1667+{-# INLINE postscanl' #-}
1669−_postscanl' :: (IsStream t, Monad m) => (b -> a -> b) -> b -> t m a -> t m b
1668+postscanl' :: (IsStream t, Monad m) => (b -> a -> b) -> b -> t m a -> t m b
1670−_postscanl' step z m = fromStreamD $ D.postscanl' step z $ toStreamD m
1669+postscanl' step z m = fromStreamD $ D.postscanl' step z $ toStreamD m
1671
1670
1672-- XXX this needs to be concurrent
1671-- XXX this needs to be concurrent
1673−-- | Like postscanl' but with a monadic step function.
1672+-- | Like 'postscanl'' but with a monadic step function.
1674--
1673--
1675−-- @since 0.6.0
1674+-- @since 0.7.0
1676−{-# INLINE _postscanlM' #-}
1675+{-# INLINE postscanlM' #-}
1677−_postscanlM' :: (IsStream t, Monad m) => (b -> a -> m b) -> b -> t m a -> t m b
1676+postscanlM' :: (IsStream t, Monad m) => (b -> a -> m b) -> b -> t m a -> t m b
1678−_postscanlM' step z m = fromStreamD $ D.postscanlM' step z $ toStreamD m
1677+postscanlM' step z m = fromStreamD $ D.postscanlM' step z $ toStreamD m
1679
1678
1680-- XXX prescanl does not sound very useful, enable only if there is a
1679-- XXX prescanl does not sound very useful, enable only if there is a
1681-- compelling use case.
1680-- compelling use case.
src/Streamly/Streams/StreamD.hs−9
@@ -1912,15 +1912,6 @@ scanlx' fstep begin done s =
1912-- postscans
1912-- postscans
1913------------------------------------------------------------------------------
1913------------------------------------------------------------------------------
1914
1914
1915−-- XXX if we make the initial value of the accumulator monadic then should we
1916−-- execute it even if the stream is empty? In that case we would have generated
1917−-- the effect but discarded the value, but that is what a fold does when the
1918−-- stream is empty. Whatever we decide, need to reconcile this with prescan.
1919−-- If we execute the initial value here without even using it then it is ok to
1920−-- execute the last step there as well without using the value.
1921−-- Looking at the duality with right fold, in case of right fold we always
1922−-- perform the action when the construction terminates, so in case of left fold
1923−-- we should perform it only when the reduction starts.
1924{-# INLINE_NORMAL postscanlM' #-}
1915{-# INLINE_NORMAL postscanlM' #-}
1925postscanlM' :: Monad m => (b -> a -> m b) -> b -> Stream m a -> Stream m b
1916postscanlM' :: Monad m => (b -> a -> m b) -> b -> Stream m a -> Stream m b
1926postscanlM' fstep begin (Stream step state) =
1917postscanlM' fstep begin (Stream step state) =