on master help sign in
Add the upgrade guide examples to haddock
9541cafHarendra Kumar
core/src/DocTestDataStream.hs+1
@@ -22,6 +22,7 @@
22>>> import qualified Streamly.Data.Array as Array
22>>> import qualified Streamly.Data.Array as Array
23>>> import qualified Streamly.Data.Fold as Fold
23>>> import qualified Streamly.Data.Fold as Fold
24>>> import qualified Streamly.Data.Stream as Stream
24>>> import qualified Streamly.Data.Stream as Stream
25+>>> import qualified Streamly.Data.StreamK as StreamK
25>>> import qualified Streamly.Data.Unfold as Unfold
26>>> import qualified Streamly.Data.Unfold as Unfold
26>>> import qualified Streamly.Data.Parser as Parser
27>>> import qualified Streamly.Data.Parser as Parser
27>>> import qualified Streamly.FileSystem.Dir as Dir
28>>> import qualified Streamly.FileSystem.Dir as Dir
core/src/Streamly/Data/Stream.hs+31−5
@@ -39,6 +39,14 @@ module Streamly.Data.Stream
39 --
39 --
40 -- See also: "Streamly.Internal.Data.Stream.Generate" for
40 -- See also: "Streamly.Internal.Data.Stream.Generate" for
41 -- @Pre-release@ functions.
41 -- @Pre-release@ functions.
42+ --
43+ -- Useful Idioms:
44+ --
45+ -- >>> fromIndices f = fmap f $ Stream.enumerateFrom 0
46+ -- >>> fromIndicesM f = Stream.mapM f $ Stream.enumerateFrom 0
47+ -- >>> fromListM = Stream.sequence . Stream.fromList
48+ -- >>> fromFoldable = StreamK.toStream . StreamK.fromFoldable
49+ -- >>> fromFoldableM = Stream.sequence . fromFoldable
42
50
43 -- ** Primitives
51 -- ** Primitives
44 -- | Primitives to construct a stream from pure values or monadic actions.
52 -- | Primitives to construct a stream from pure values or monadic actions.
@@ -253,6 +261,14 @@ module Streamly.Data.Stream
253 -}
261 -}
254
262
255 -- ** Scanning By 'Fold'
263 -- ** Scanning By 'Fold'
264+ -- | Useful idioms:
265+ --
266+ -- >>> scanl' f z = Stream.scan (Fold.foldl' f z)
267+ -- >>> scanlM' f z = Stream.scan (Fold.foldlM' f z)
268+ -- >>> postscanl' f z = Stream.postscan (Fold.foldl' f z)
269+ -- >>> postscanlM' f z = Stream.postscan (Fold.foldlM' f z)
270+ -- >>> scanl1' f = Stream.catMaybes . Stream.scan (Fold.foldl1' f)
271+ -- >>> scanl1M' f = Stream.catMaybes . Stream.scan (Fold.foldlM1' f)
256 , scan
272 , scan
257 , postscan
273 , postscan
258 -- XXX postscan1 can be implemented using Monoids or Refolds.
274 -- XXX postscan1 can be implemented using Monoids or Refolds.
@@ -298,6 +314,13 @@ module Streamly.Data.Stream
298 -- filtering folds (folds returning a 'Maybe' type) in
314 -- filtering folds (folds returning a 'Maybe' type) in
299 -- "Streamly.Internal.Data.Fold" can be used along with 'scanMaybe' to
315 -- "Streamly.Internal.Data.Fold" can be used along with 'scanMaybe' to
300 -- perform stateful filtering operations in general.
316 -- perform stateful filtering operations in general.
317+ --
318+ -- Useful idioms:
319+ --
320+ -- >>> deleteBy cmp x = Stream.scanMaybe (Fold.deleteBy cmp x)
321+ -- >>> findIndices p = Stream.scanMaybe (Fold.findIndices p)
322+ -- >>> elemIndices a = findIndices (== a)
323+ -- >>> uniq = Stream.scanMaybe (Fold.uniqBy (==))
301 , scanMaybe
324 , scanMaybe
302 , take
325 , take
303 , takeWhile
326 , takeWhile
@@ -399,6 +422,14 @@ module Streamly.Data.Stream
399 , concatMapM
422 , concatMapM
400
423
401 -- * Repeated Fold
424 -- * Repeated Fold
425+ -- | Useful idioms:
426+ --
427+ -- >>> splitWithSuffix p f = Stream.foldMany (Fold.takeEndBy p f)
428+ -- >>> splitOnSuffix p f = Stream.foldMany (Fold.takeEndBy_ p f)
429+ -- >>> groupsBy eq f = Stream.parseMany (Parser.groupBy eq f)
430+ -- >>> groupsByRolling eq f = Stream.parseMany (Parser.groupByRolling eq f)
431+ -- >>> wordsBy p f = Stream.parseMany (Parser.wordBy p f)
432+ -- >>> groupsOf n f = Stream.foldMany (Fold.take n f)
402 , foldMany -- XXX Rename to foldRepeat
433 , foldMany -- XXX Rename to foldRepeat
403 , parseMany
434 , parseMany
404 , Array.chunksOf
435 , Array.chunksOf
@@ -574,8 +605,3 @@ import Prelude
574--
605--
575-- 'Stream' and 'StreamK' types can be interconverted. See
606-- 'Stream' and 'StreamK' types can be interconverted. See
576-- "Streamly.Data.StreamK" module for conversion operations.
607-- "Streamly.Data.StreamK" module for conversion operations.
577−--
578−-- == Useful Idioms
579−--
580−-- >>> fromListM = Stream.sequence . Stream.fromList
581−-- >>> fromIndices f = fmap f $ Stream.enumerateFrom 0
core/src/Streamly/Data/StreamK.hs+6
@@ -14,6 +14,12 @@
14--
14--
15-- Please refer to "Streamly.Internal.Data.Stream.StreamK" for more functions
15-- Please refer to "Streamly.Internal.Data.Stream.StreamK" for more functions
16-- that have not yet been released.
16-- that have not yet been released.
17+--
18+-- Some useful idioms:
19+--
20+-- >>> concatFoldableWith f = Prelude.foldr f StreamK.nil
21+-- >>> concatMapFoldableWith f g = Prelude.foldr (f . g) StreamK.nil
22+-- >>> concatForFoldableWith f xs g = Prelude.foldr (f . g) StreamK.nil xs
17
23
18-- Notes:
24-- Notes:
19--
25--
src/Streamly/Internal/Data/Stream/Concurrent.hs+12−1
@@ -132,6 +132,7 @@ import Streamly.Internal.Data.Stream.Concurrent.Channel
132-- >>> import qualified Streamly.Data.Array as Array
132-- >>> import qualified Streamly.Data.Array as Array
133-- >>> import qualified Streamly.Data.Fold as Fold
133-- >>> import qualified Streamly.Data.Fold as Fold
134-- >>> import qualified Streamly.Data.Parser as Parser
134-- >>> import qualified Streamly.Data.Parser as Parser
135+-- >>> import qualified Streamly.Data.StreamK as StreamK
135-- >>> import qualified Streamly.Internal.Data.Stream as Stream hiding (append2)
136-- >>> import qualified Streamly.Internal.Data.Stream as Stream hiding (append2)
136-- >>> import qualified Streamly.Internal.Data.Stream.Concurrent as Stream
137-- >>> import qualified Streamly.Internal.Data.Stream.Concurrent as Stream
137-- >>> import Prelude hiding (concatMap, concat, zipWith)
138-- >>> import Prelude hiding (concatMap, concat, zipWith)
@@ -176,6 +177,10 @@ parEvalD modifier m = D.Stream step Nothing
176-- multiple streams won't apply here e.g. maxThreads, eager, interleaved,
177-- multiple streams won't apply here e.g. maxThreads, eager, interleaved,
177-- ordered, stopWhen options won't have any effect.
178-- ordered, stopWhen options won't have any effect.
178--
179--
180+-- Useful idioms:
181+--
182+-- >>> parUnfoldrM step = Stream.parEval id . Stream.unfoldrM step
183+-- >>> parIterateM step = Stream.parEval id . Stream.iterateM step
179{-# INLINE parEval #-}
184{-# INLINE parEval #-}
180parEval :: MonadAsync m => (Config -> Config) -> Stream m a -> Stream m a
185parEval :: MonadAsync m => (Config -> Config) -> Stream m a -> Stream m a
181parEval modifier input = withChannel modifier input (const id)
186parEval modifier input = withChannel modifier input (const id)
@@ -539,9 +544,15 @@ parMapM :: MonadAsync m =>
539 (Config -> Config) -> (a -> m b) -> Stream m a -> Stream m b
544 (Config -> Config) -> (a -> m b) -> Stream m a -> Stream m b
540parMapM modifier f = parConcatMap modifier (Stream.fromEffect . f)
545parMapM modifier f = parConcatMap modifier (Stream.fromEffect . f)
541
546
542−-- |
547+-- | Definition:
548+--
543-- >>> parSequence modifier = Stream.parMapM modifier id
549-- >>> parSequence modifier = Stream.parMapM modifier id
544--
550--
551+-- Useful idioms:
552+--
553+-- >>> parFromListM = Stream.parSequence id . Stream.fromList
554+-- >>> parFromFoldableM = Stream.parSequence id . StreamK.toStream . StreamK.fromFoldable
555+--
545{-# INLINE parSequence #-}
556{-# INLINE parSequence #-}
546parSequence :: MonadAsync m =>
557parSequence :: MonadAsync m =>
547 (Config -> Config) -> Stream m (m a) -> Stream m a
558 (Config -> Config) -> Stream m (m a) -> Stream m a