2-- Module : Streamly.Data.Stream.MkType
3-- Copyright : (c) 2022 Composewell Technologies
4-- License : BSD-3-Clause
5-- Maintainer : streamly@composewell.com
9-- Template Haskell macros to create custom newtype wrappers for the 'Stream'
10-- type. See the examples below to create the standard stream types that were
11-- available in streamly versions before 0.9.0.
13-- To use this module, the following extensions must be enabled:
15-- >>> :set -XStandaloneDeriving
16-- >>> :set -XTemplateHaskell
17-- >>> :set -XTypeFamilies
18-- >>> :set -XUndecidableInstances
20-- Import this module unqualified to bring everything needed in scope without
21-- having to import several other modules. Also, "Streamly.Data.Stream" or
22-- "Streamly.Data.Stream.Prelude" must be imported @as Stream@.
24-- >>> import Streamly.Data.Stream.MkType
25-- >>> import qualified Streamly.Data.Stream.Prelude as Stream
27-- For 'Streamly.Prelude.AsyncT' monad type with a concurrent cross product
31-- bind = flip (Stream.parConcatMap id)
32-- $(mkCrossType "AsyncT" "bind" True)
35-- For 'Streamly.Prelude.WAsyncT' monad type with a concurrent interleaved
39-- bind = flip (Stream.parConcatMap (Stream.interleaved True))
40-- $(mkCrossType "WAsyncT" "bind" True)
43-- For 'Streamly.Prelude.AheadT' monad type with a concurrent ordered
47-- bind = flip (Stream.parConcatMap (Stream.ordered True))
48-- $(mkCrossType "AheadT" "bind" True)
51-- For 'Streamly.Prelude.ParallelT' monad type with an eager concurrent cross
55-- parBind = flip (Stream.parConcatMap (Stream.eager True))
56-- $(mkCrossType "ParallelT" "parBind" True)
59-- For 'Streamly.Prelude.ZipSerialM' serial zipping applicative type:
62-- zipApply = Stream.zipWith ($)
63-- $(mkZipType "ZipSerialM" "zipApply" False)
66-- For 'Streamly.Prelude.ZipAsync' concurrent zipping applicative type:
69-- parApply = Stream.parApply id
70-- $(mkZipType "ZipAsync" "parApply" True)
73-- Instead of using these macros directly you could use the generated code as
74-- well. Use these macros in ghci to generate the required code and paste it in
75-- your package, you can customize the code as desired. See the docs of the
76-- macros below for examples about how to view the generated code. For example:
78-- >>> bind = flip (Stream.parConcatMap id)
79-- >>> expr <- runQ (mkCrossType "AsyncT" "bind" True)
81-- >> putStrLn $ pprint expr
83module Streamly.Data.Stream.MkType
85 -- * Imports for Examples
88 -- * Template Haskell Macros
105import Data.Functor.Identity (Identity)
106import GHC.Exts (IsList, IsString)
107import Text.Read (Read(..))
109import Streamly.Internal.Data.Stream.MkType
113-- >>> import Language.Haskell.TH
114-- >>> import qualified Streamly.Data.Stream.Prelude as Stream
115-- >>> import Streamly.Data.Stream.MkType
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list