@@ -39,6 +39,14 @@ module Streamly.Data.Stream
3939 --
4040 -- See also: "Streamly.Internal.Data.Stream.Generate" for
4141 -- @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
4250
4351 -- ** Primitives
4452 -- | Primitives to construct a stream from pure values or monadic actions.
@@ -253,6 +261,14 @@ module Streamly.Data.Stream
253261 -}
254262
255263 -- ** 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)
256272 , scan
257273 , postscan
258274 -- XXX postscan1 can be implemented using Monoids or Refolds.
@@ -298,6 +314,13 @@ module Streamly.Data.Stream
298314 -- filtering folds (folds returning a 'Maybe' type) in
299315 -- "Streamly.Internal.Data.Fold" can be used along with 'scanMaybe' to
300316 -- 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 (==))
301324 , scanMaybe
302325 , take
303326 , takeWhile
@@ -399,6 +422,14 @@ module Streamly.Data.Stream
399422 , concatMapM
400423
401424 -- * 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)
402433 , foldMany -- XXX Rename to foldRepeat
403434 , parseMany
404435 , Array.chunksOf
@@ -574,8 +605,3 @@ import Prelude
574605--
575606-- 'Stream' and 'StreamK' types can be interconverted. See
576607-- "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