on master help sign in
Add deriving examples of all old stream types
99ff010Harendra Kumar
src/Streamly/Data/Stream/MkType.hs+41−10
@@ -7,7 +7,8 @@
7-- Portability : GHC
7-- Portability : GHC
8--
8--
9-- Template Haskell macros to create custom newtype wrappers for the 'Stream'
9-- Template Haskell macros to create custom newtype wrappers for the 'Stream'
10−-- type, deriving all the usual instances.
10+-- type. See the examples below to create the standard stream types that were
11+-- available in streamly versions before 0.9.0.
11--
12--
12-- To use this module, the following extensions must be enabled:
13-- To use this module, the following extensions must be enabled:
13--
14--
@@ -23,31 +24,61 @@
23-- >>> import Streamly.Data.Stream.MkType
24-- >>> import Streamly.Data.Stream.MkType
24-- >>> import qualified Streamly.Data.Stream.Prelude as Stream
25-- >>> import qualified Streamly.Data.Stream.Prelude as Stream
25--
26--
26−-- Example, create an applicative type with zipping apply:
27+-- For 'Streamly.Prelude.AsyncT' monad type with a concurrent cross product
28+-- bind:
27--
29--
28-- >>> :{
30-- >>> :{
29−-- zipApply = Stream.zipWith ($)
31+-- bind = flip (Stream.parConcatMap id)
30−-- $(mkZipType "ZipStream" "zipApply" False)
32+-- $(mkCrossType "AsyncT" "bind" True)
31-- :}
33-- :}
32--
34--
33−-- Example, create an applicative type with concurrent zipping apply:
35+-- For 'Streamly.Prelude.WAsyncT' monad type with a concurrent interleaved
36+-- bind:
34--
37--
35-- >>> :{
38-- >>> :{
36−-- parApply = Stream.parApply id
39+-- bind = flip (Stream.parConcatMap (Stream.interleaved True))
37−-- $(mkZipType "ParZipStream" "parApply" True)
40+-- $(mkCrossType "WAsyncT" "bind" True)
38-- :}
41-- :}
39--
42--
43+-- For 'Streamly.Prelude.AheadT' monad type with a concurrent ordered
44+-- cross product bind:
45+--
46+-- >>> :{
47+-- bind = flip (Stream.parConcatMap (Stream.ordered True))
48+-- $(mkCrossType "AheadT" "bind" True)
49+-- :}
50+--
40−-- Example, create a monad type with an eager concurrent cross product bind:
51+-- For 'Streamly.Prelude.ParallelT' monad type with an eager concurrent cross
52+-- product bind:
41--
53--
42-- >>> :{
54-- >>> :{
43-- parBind = flip (Stream.parConcatMap (Stream.eager True))
55-- parBind = flip (Stream.parConcatMap (Stream.eager True))
44−-- $(mkCrossType "ParEagerStream" "parBind" True)
56+-- $(mkCrossType "ParallelT" "parBind" True)
57+-- :}
58+--
59+-- For 'Streamly.Prelude.ZipSerialM' serial zipping applicative type:
60+--
61+-- >>> :{
62+-- zipApply = Stream.zipWith ($)
63+-- $(mkZipType "ZipSerialM" "zipApply" False)
64+-- :}
65+--
66+-- For 'Streamly.Prelude.ZipAsync' concurrent zipping applicative type:
67+--
68+-- >>> :{
69+-- parApply = Stream.parApply id
70+-- $(mkZipType "ZipAsync" "parApply" True)
45-- :}
71-- :}
46--
72--
47-- Instead of using these macros directly you could use the generated code as
73-- Instead of using these macros directly you could use the generated code as
48-- well. Use these macros in ghci to generate the required code and paste it in
74-- well. Use these macros in ghci to generate the required code and paste it in
49-- your package, you can customize the code as desired. See the docs of the
75-- your package, you can customize the code as desired. See the docs of the
50−-- macros below for examples about how to view the generated code.
76+-- macros below for examples about how to view the generated code. For example:
77+--
78+-- >>> bind = flip (Stream.parConcatMap id)
79+-- >>> expr <- runQ (mkCrossType "AsyncT" "bind" True)
80+--
81+-- >> putStrLn $ pprint expr
51--
82--
52module Streamly.Data.Stream.MkType
83module Streamly.Data.Stream.MkType
53 (
84 (