Skip to content

Commit 324198d

Browse files
Update docs, add constructor/deconstructor info (MkType)
1 parent d6619e1 commit 324198d

File tree

1 file changed

+50
-16
lines changed

1 file changed

+50
-16
lines changed

src/Streamly/Data/Stream/MkType.hs

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,47 +31,66 @@
3131
--
3232
-- == Parallel
3333
--
34-
-- An unordered concurrent version of the serial 'Nested' type. Runs multiple
35-
-- iterations of the nested loops concurrently, iterations may execute out of
36-
-- order. More outer iterations are started only if the existing inner
37-
-- iterations are not saturating the resources.
34+
-- A newtype wrapper over the 'Stream' type; the Applicative and Monad
35+
-- instances generate a cross product of the two streams in a concurrent
36+
-- manner. The order in which the stream elements are produced is not
37+
-- deterministic, this is supposed to be used if order does not matter.
38+
39+
-- Loops over the outer stream, generating multiple elements concurrently; for
40+
-- each outer stream element, loop over the inner stream concurrently. More
41+
-- outer iterations are started only if the existing inner iterations are not
42+
-- saturating the resources.
43+
--
44+
-- Use 'mkParallel' to construct from 'Stream' type and 'unParallel' to
45+
-- deconstruct back to 'Stream'.
3846
--
3947
-- >>> :{
48+
-- bind :: MonadAsync m => Stream m a -> (a -> Stream m b) -> Stream m b
4049
-- bind = flip (Stream.parConcatMap id)
4150
-- $(mkCrossType "Parallel" "bind" True)
4251
-- :}
4352
--
4453
-- This is a bounded concurrent, unordered list-transformer (ListT) monad.
4554
--
4655
-- WARNING! By design, monad bind of this type is not associative, because of
47-
-- concurrency order of effects as well as results may be unpredictable.
56+
-- concurrency, order of effects as well as results is non-deterministic.
4857
--
49-
-- Same as the deprecated 'Streamly.Prelude.AsyncT' type.
58+
-- Serves the same purpose as the 'Streamly.Prelude.AsyncT' type in older
59+
-- releases.
5060
--
5161
-- == FairParallel
5262
--
5363
-- Like Parallel but strikes a balance between going deeper into existing
54-
-- iterations of the loop and starting new iterations.
64+
-- iterations of the loop and starting new outer loop iterations.
65+
--
66+
-- Use 'mkFairParallel' to construct from 'Stream' type and 'unFairParallel' to
67+
-- deconstruct back to 'Stream'.
5568
--
5669
-- >>> :{
70+
-- bind :: MonadAsync m => Stream m a -> (a -> Stream m b) -> Stream m b
5771
-- bind = flip (Stream.parConcatMap (Stream.interleaved True))
5872
-- $(mkCrossType "FairParallel" "bind" True)
5973
-- :}
6074
--
6175
-- This is a bounded concurrent, fair logic programming (LogicT) monad.
6276
--
6377
-- WARNING! By design, monad bind of this type is not associative, because of
64-
-- concurrency order of effects as well as results may be unpredictable.
78+
-- concurrency, order of effects as well as results may be unpredictable.
6579
--
66-
-- Same as the deprecated 'Streamly.Prelude.WAsyncT' type.
80+
-- Serves the same purpose as the 'Streamly.Prelude.WAsyncT' type in older
81+
-- releases.
6782
--
6883
-- == EagerParallel
6984
--
7085
-- Like Parallel, but executes as many actions concurrently as possible. This
7186
-- is useful if you want all actions to be scheduled at the same time so that
7287
-- something does not get starved due to others.
7388
--
89+
-- Use 'mkEagerParallel' to construct from 'Stream' type and 'unEagerParallel'
90+
-- to deconstruct back to 'Stream'.
91+
--
7492
-- >>> :{
93+
-- bind :: MonadAsync m => Stream m a -> (a -> Stream m b) -> Stream m b
7594
-- parBind = flip (Stream.parConcatMap (Stream.eager True))
7695
-- $(mkCrossType "EagerParallel" "parBind" True)
7796
-- :}
@@ -81,7 +100,8 @@
81100
-- WARNING! By design, monad bind of this type is not associative, because of
82101
-- concurrency order of effects as well as results may be unpredictable.
83102
--
84-
-- Same as the deprecated 'Streamly.Prelude.ParallelT' type.
103+
-- Serves the same purpose as the 'Streamly.Prelude.ParallelT' type in older
104+
-- releases.
85105
--
86106
-- == OrderedParallel
87107
--
@@ -90,7 +110,11 @@
90110
-- specified in the code. This is closest to the serial Nested type in behavior
91111
-- among all the concurrent types.
92112
--
113+
-- Use 'mkOrderedParallel' to construct from 'Stream' type and
114+
-- 'unOrderedParallel' to deconstruct back to 'Stream'.
115+
--
93116
-- >>> :{
117+
-- bind :: MonadAsync m => Stream m a -> (a -> Stream m b) -> Stream m b
94118
-- bind = flip (Stream.parConcatMap (Stream.ordered True))
95119
-- $(mkCrossType "OrderedParallel" "bind" True)
96120
-- :}
@@ -100,26 +124,36 @@
100124
-- WARNING! Monad bind of this type is associative for values, but because of
101125
-- concurrency, order of effects may be unpredictable.
102126
--
103-
-- Same as the deprecated 'Streamly.Prelude.AheadT' type.
127+
-- Serves the same purpose as the 'Streamly.Prelude.AheadT' type in older
128+
-- releases.
104129
--
105130
-- == Zip
106131
--
107-
-- An applicative type to zip two streams.
132+
-- A newtype wrapper over the 'Stream' type, the applicative instance zips two
133+
-- streams.
134+
--
135+
-- Use 'mkZip' to construct from 'Stream' type and 'unZip' to deconstruct back
136+
-- to 'Stream'.
108137
--
109138
-- >>> :{
139+
-- zipApply :: Monad m => Stream m (a -> b) -> Stream m a -> Stream m b
110140
-- zipApply = Stream.zipWith ($)
111141
-- $(mkZipType "Zip" "zipApply" False)
112142
-- :}
113143
--
114144
-- Same as the deprcated 'Streamly.Prelude.ZipSerialM' type.
115145
--
116-
-- == ParZip
146+
-- == ZipParallel
147+
--
148+
-- Like Zip but evaluates the streams being zipped concurrently.
117149
--
118-
-- Like Zip but evaluates the two streams concurrently.
150+
-- Use 'mkZipParallel' to construct from 'Stream' type and 'unZipParallel' to
151+
-- deconstruct back to 'Stream'.
119152
--
120153
-- >>> :{
121-
-- parCrossApply = Stream.parCrossApply id
122-
-- $(mkZipType "ParZip" "parCrossApply" True)
154+
-- parZipApply :: MonadAsync m => Stream m (a -> b) -> Stream m a -> Stream m b
155+
-- parZipApply = Stream.parZipWith id id
156+
-- $(mkZipType "ZipParallel" "parZipApply" True)
123157
-- :}
124158
--
125159
-- Same as the deprecated 'Streamly.Prelude.ZipAsync' type.

0 commit comments

Comments
 (0)