on master help sign in
Improve documentation of scan routines and "before"

Add definitions illustrating relationships between different combinators.

commit9148b4d65b5d6f0811c134763dbdab0dfdceca3a authorHarendra Kumar <harendra@composewell.com> dateSun 8 Aug 2021, 02:16 (5 years ago) parent1af9389
4 files changed+17−3
.github/workflows/haskell.yml+1−1 src/Streamly/Internal/Data/Stream/IsStream/Common.hs+2 src/Streamly/Internal/Data/Stream/IsStream/Exception.hs+9−1 src/Streamly/Internal/Data/Stream/IsStream/Transform.hs+5−1
.github/workflows/haskell.yml+1−1
@@ -158,7 +158,7 @@ jobs:
158158 cabal update
159159 cabal build all
160160 $HOME/.cabal/bin/cabal-docspec --version
161− $HOME/.cabal/bin/cabal-docspec --timeout 60
161+ $HOME/.cabal/bin/cabal-docspec --timeout 60 --check-properties --property-variables xs
162162 elif test -z "$COVERAGE"
163163 then
164164 export TOOLS_DIR=/opt
src/Streamly/Internal/Data/Stream/IsStream/Common.hs+2
@@ -313,6 +313,8 @@ scanlMAfter' step initial done stream =
313313-- XXX this needs to be concurrent
314314-- | Like 'postscanl'' but with a monadic step function and a monadic seed.
315315--
316+-- >>> postscanlM' f z xs = Stream.drop 1 $ Stream.scanlM' f z xs
317+--
316318-- /Since: 0.7.0/
317319--
318320-- /Since: 0.8.0 (signature change)/
src/Streamly/Internal/Data/Stream/IsStream/Exception.hs+9−1
@@ -34,13 +34,21 @@ import Streamly.Internal.Data.SVar (MonadAsync)
3434
3535import qualified Streamly.Internal.Data.Stream.StreamD as D
3636
37+-- $setup
38+-- >>> :m
39+-- >>> import qualified Streamly.Prelude as Stream
40+-- >>> import qualified Streamly.Internal.Data.Stream.IsStream as Stream (nilM)
41+
3742------------------------------------------------------------------------------
3843-- Exceptions
3944------------------------------------------------------------------------------
4045
4146-- | Run the action @m b@ before the stream yields its first element.
4247--
43−-- > before action xs = 'nilM' action <> xs
48+-- Same as the following but more efficient due to fusion:
49+--
50+-- >>> before action xs = Stream.nilM action <> xs
51+-- >>> before action xs = Stream.concatMap (const xs) (Stream.fromEffect action)
4452--
4553-- @since 0.7.0
4654{-# INLINE before #-}
src/Streamly/Internal/Data/Stream/IsStream/Transform.hs+5−1
@@ -713,6 +713,9 @@ scanlM' step begin m = fromStreamD $ D.scanlM' step begin $ toStreamD m
713713-- lazy expressions inside the accumulator, it is recommended that a strict
714714-- data structure is used for accumulator.
715715--
716+-- >>> scanl' f z xs = scanlM' (\a b -> return (f a b)) (return z) xs
717+-- >>> scanl' f z xs = z `Stream.cons` postscanl' f z xs
718+--
716719-- See also: 'usingStateT'
717720--
718721-- @since 0.2.0
@@ -722,7 +725,8 @@ scanl' step z m = fromStreamS $ S.scanl' step z $ toStreamS m
722725
723726-- | Like 'scanl'' but does not stream the initial value of the accumulator.
724727--
725−-- > postscanl' f z xs = Stream.drop 1 $ Stream.scanl' f z xs
728+-- >>> postscanl' f z = postscanlM' (\a b -> return (f a b)) (return z)
729+-- >>> postscanl' f z xs = Stream.drop 1 $ Stream.scanl' f z xs
726730--
727731-- @since 0.7.0
728732{-# INLINE postscanl' #-}