on master help sign in
Make small updates to stream/parser module overview
a11e92bHarendra Kumar
core/src/Streamly/Data/Parser.hs+5−1
@@ -11,7 +11,11 @@
11-- interconverted.
11-- interconverted.
12--
12--
13-- Note that these parsers do not report the error context (e.g. line number or
13-- 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.
15--
19--
16module Streamly.Data.Parser
20module Streamly.Data.Parser
17 (
21 (
core/src/Streamly/Data/Stream.hs+6−10
@@ -29,18 +29,17 @@
29-- allows high performance combinatorial programming even when using byte level
29-- allows high performance combinatorial programming even when using byte level
30-- streams. Streamly API is similar to Haskell lists.
30-- streams. Streamly API is similar to Haskell lists.
31--
31--
32−-- Streams can be constructed
33−-- like lists, except that they use 'nil' instead of '[]' and 'cons' instead of
32+-- Streams can be constructed like lists, except that they use 'nil' instead of
34−-- ':'.
33+-- '[]' and 'cons' instead of ':'.
35--
34--
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:
37--
36--
38-- >>> import Streamly.Data.Stream (Stream, cons, consM, nil)
37-- >>> import Streamly.Data.Stream (Stream, cons, consM, nil)
39-- >>> stream = 1 `cons` 2 `cons` nil :: Stream IO Int
38-- >>> stream = 1 `cons` 2 `cons` nil :: Stream IO Int
40-- >>> Stream.fold Fold.toList stream -- IO [Int]
39-- >>> Stream.fold Fold.toList stream -- IO [Int]
41-- [1,2]
40-- [1,2]
42--
41--
43−-- 'consM' constructs a stream from effectful actions:
42+-- `consM` adds an effect at the head of the stream:
44--
43--
45-- >>> stream = effect 1 `consM` effect 2 `consM` nil
44-- >>> stream = effect 1 `consM` effect 2 `consM` nil
46-- >>> Stream.fold Fold.toList stream
45-- >>> Stream.fold Fold.toList stream
@@ -60,8 +59,7 @@
60--
59--
61-- >>> :{
60-- >>> :{
62-- echo =
61-- echo =
63−-- Stream.repeat getLine -- Stream IO (IO String)
64−-- & Stream.sequence -- Stream IO String
62+-- Stream.repeatM getLine -- Stream IO String
65-- & Stream.mapM putStrLn -- Stream IO ()
63-- & Stream.mapM putStrLn -- Stream IO ()
66-- & Stream.fold Fold.drain -- IO ()
64-- & Stream.fold Fold.drain -- IO ()
67-- :}
65-- :}
@@ -75,10 +73,8 @@
75-- "Data.List" like functions and many more powerful combinators to perform
73-- "Data.List" like functions and many more powerful combinators to perform
76-- common programming tasks.
74-- common programming tasks.
77--
75--
78−-- Some common idioms:
76+-- == Useful Idioms
79--
77--
80−-- >>> repeatM = Stream.sequence . Stream.repeat
81−-- >>> replicateM n = Stream.sequence . Stream.replicate n
82-- >>> fromListM = Stream.sequence . Stream.fromList
78-- >>> fromListM = Stream.sequence . Stream.fromList
83-- >>> fromFoldableM = Stream.sequence . Stream.fromFoldable
79-- >>> fromFoldableM = Stream.sequence . Stream.fromFoldable
84-- >>> fromIndices f = fmap f $ Stream.enumerateFrom 0
80-- >>> fromIndices f = fmap f $ Stream.enumerateFrom 0