on master help sign in
Expose postscanl' and postscanlM'
commit3ae0b40dc7c9ba94c7cf2ccf828f3a8aee76e123 authorHarendra Kumar <harendra.kumar@gmail.com> dateWed 19 Jun 2019, 21:09 (7 years ago) parent24b044a
3 files changed+14−23
Changelog.md+1 src/Streamly/Prelude.hs+13−14 src/Streamly/Streams/StreamD.hs−9
Changelog.md+1
@@ -63,6 +63,7 @@ example, concat streams concurrently using this.
6363* Add the following to `Streamly.Prelude`:
6464 * `foldrS` to fold a stream to a stream
6565 * `foldrT` to fold a stream to an arbitrary transformer monad
66+ * `postscanl'` and `postscanlM'`
6667 * `reverse'` a several times faster reverse using Storable instance
6768 * `intersperseByTime` intersperse a mondadic action in a stream
6869 periodically
src/Streamly/Prelude.hs+13−14
@@ -313,8 +313,8 @@ module Streamly.Prelude
313313
314314 , scanl'
315315 , scanlM'
316− -- , postscanl'
317− -- , postscanlM'
316+ , postscanl'
317+ , postscanlM'
318318 -- , prescanl'
319319 -- , prescanlM'
320320 , scanl1'
@@ -1659,23 +1659,22 @@ scanlM' step begin m = fromStreamD $ D.scanlM' step begin $ toStreamD m
16591659scanl' :: (IsStream t, Monad m) => (b -> a -> b) -> b -> t m a -> t m b
16601660scanl' step z m = fromStreamS $ S.scanl' step z $ toStreamS m
16611661
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.
16641663--
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
16661665--
1667−-- @since 0.6.0
1668−{-# INLINE _postscanl' #-}
1669−_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
1666+-- @since 0.7.0
1667+{-# INLINE postscanl' #-}
1668+postscanl' :: (IsStream t, Monad m) => (b -> a -> b) -> b -> t m a -> t m b
1669+postscanl' step z m = fromStreamD $ D.postscanl' step z $ toStreamD m
16711670
16721671-- XXX this needs to be concurrent
1673−-- | Like postscanl' but with a monadic step function.
1672+-- | Like 'postscanl'' but with a monadic step function.
16741673--
1675−-- @since 0.6.0
1676−{-# INLINE _postscanlM' #-}
1677−_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
1674+-- @since 0.7.0
1675+{-# INLINE postscanlM' #-}
1676+postscanlM' :: (IsStream t, Monad m) => (b -> a -> m b) -> b -> t m a -> t m b
1677+postscanlM' step z m = fromStreamD $ D.postscanlM' step z $ toStreamD m
16791678
16801679-- XXX prescanl does not sound very useful, enable only if there is a
16811680-- compelling use case.
src/Streamly/Streams/StreamD.hs−9
@@ -1912,15 +1912,6 @@ scanlx' fstep begin done s =
19121912-- postscans
19131913------------------------------------------------------------------------------
19141914
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.
19241915{-# INLINE_NORMAL postscanlM' #-}
19251916postscanlM' :: Monad m => (b -> a -> m b) -> b -> Stream m a -> Stream m b
19261917postscanlM' fstep begin (Stream step state) =