on master help sign in
Make small updates to stream/parser module overview
commita11e92b963f1fc672493c86ab6e668a63e8daf90 authorHarendra Kumar <harendra@composewell.com> dateThu 17 Nov 2022, 13:12 (4 years ago) parent50a3012
2 files changed+11−11
core/src/Streamly/Data/Parser.hs+5−1 core/src/Streamly/Data/Stream.hs+6−10
core/src/Streamly/Data/Parser.hs+5−1
@@ -11,7 +11,11 @@
1111-- interconverted.
1212--
1313-- Note that these parsers do not report the error context (e.g. line number or
14−-- column). Though this can be supported in future.
14+-- column). This may be supported in future.
15+--
16+-- mtl instances are not provided. If the 'Parser' type is the top most layer
17+-- (which should be the case almost always) you can just use 'fromEffect' to
18+-- execute the lower layer monad effects.
1519--
1620module Streamly.Data.Parser
1721 (
core/src/Streamly/Data/Stream.hs+6−10
@@ -29,18 +29,17 @@
2929-- allows high performance combinatorial programming even when using byte level
3030-- streams. Streamly API is similar to Haskell lists.
3131--
32−-- Streams can be constructed
33−-- like lists, except that they use 'nil' instead of '[]' and 'cons' instead of
34−-- ':'.
32+-- Streams can be constructed like lists, except that they use 'nil' instead of
33+-- '[]' and 'cons' instead of ':'.
3534--
36−-- `cons` constructs a pure stream which is more or less the same as a list:
35+-- `cons` adds a pure value at the head of the stream:
3736--
3837-- >>> import Streamly.Data.Stream (Stream, cons, consM, nil)
3938-- >>> stream = 1 `cons` 2 `cons` nil :: Stream IO Int
4039-- >>> Stream.fold Fold.toList stream -- IO [Int]
4140-- [1,2]
4241--
43−-- 'consM' constructs a stream from effectful actions:
42+-- `consM` adds an effect at the head of the stream:
4443--
4544-- >>> stream = effect 1 `consM` effect 2 `consM` nil
4645-- >>> Stream.fold Fold.toList stream
@@ -60,8 +59,7 @@
6059--
6160-- >>> :{
6261-- echo =
63−-- Stream.repeat getLine -- Stream IO (IO String)
64−-- & Stream.sequence -- Stream IO String
62+-- Stream.repeatM getLine -- Stream IO String
6563-- & Stream.mapM putStrLn -- Stream IO ()
6664-- & Stream.fold Fold.drain -- IO ()
6765-- :}
@@ -75,10 +73,8 @@
7573-- "Data.List" like functions and many more powerful combinators to perform
7674-- common programming tasks.
7775--
78−-- Some common idioms:
76+-- == Useful Idioms
7977--
80−-- >>> repeatM = Stream.sequence . Stream.repeat
81−-- >>> replicateM n = Stream.sequence . Stream.replicate n
8278-- >>> fromListM = Stream.sequence . Stream.fromList
8379-- >>> fromFoldableM = Stream.sequence . Stream.fromFoldable
8480-- >>> fromIndices f = fmap f $ Stream.enumerateFrom 0