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, deriving all the usual instances.
12-- To use this module, the following extensions must be enabled:
14-- >>> :set -XStandaloneDeriving
15-- >>> :set -XTemplateHaskell
16-- >>> :set -XTypeFamilies
17-- >>> :set -XUndecidableInstances
19-- Import this module unqualified to bring everything needed in scope without
20-- having to import several other modules. Also, "Streamly.Data.Stream" or
21-- "Streamly.Data.Stream.Prelude" must be imported @as Stream@.
23-- >>> import Streamly.Data.Stream.MkType
24-- >>> import qualified Streamly.Data.Stream.Prelude as Stream
26-- Example, create an applicative type with zipping apply:
29-- zipApply = Stream.zipWith ($)
30-- $(mkZipType "ZipStream" "zipApply" False)
33-- Example, create an applicative type with concurrent zipping apply:
36-- parApply = Stream.parApply id
37-- $(mkZipType "ParZipStream" "parApply" True)
40-- Example, create a monad type with an eager concurrent cross product bind:
43-- parBind = flip (Stream.parConcatMap (Stream.eager True))
44-- $(mkCrossType "ParEagerStream" "parBind" True)
47-- 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
49-- 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.
52module Streamly.Data.Stream.MkType
54 -- * Imports for Examples
57 -- * Template Haskell Macros
74import Data.Functor.Identity (Identity)
75import GHC.Exts (IsList, IsString)
76import Text.Read (Read(..))
78import Streamly.Internal.Data.Stream.MkType
82-- >>> import Language.Haskell.TH
83-- >>> import qualified Streamly.Data.Stream.Prelude as Stream
84-- >>> 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