3-- Module : Streamly.Data.StreamK
4-- Copyright : (c) 2017 Composewell Technologies
7-- Maintainer : streamly@composewell.com
11-- Streams using Continuation Passing Style (CPS). See the @Stream vs StreamK@
12-- section in the "Streamly.Data.Stream" module to know when to use this
15-- Please refer to "Streamly.Internal.Data.Stream.StreamK" for more functions
16-- that have not yet been released.
20-- >>> concatFoldableWith f = Prelude.foldr f StreamK.nil
21-- >>> concatMapFoldableWith f g = Prelude.foldr (f . g) StreamK.nil
22-- >>> concatForFoldableWith f xs g = Prelude.foldr (f . g) StreamK.nil xs
26-- primitive/open loop operations that can be used recursively e.g. uncons,
27-- foldBreak, parseBreak should not be converted from StreamD for use in
28-- StreamK, instead native StreamK impl should be used.
30-- Closed loop operations like repeat, replicate, iterate etc can be converted
33-- In the last phase any operation like (toStreamK . f . toStreamD) should be
34-- rewritten to a K version of f.
35-- XXX Need to add rewrite rules for all missing StreamD operations.
37module Streamly.Data.StreamK
40 -- | To execute the code examples provided in this module in ghci, please
41 -- run the following commands first.
53 -- | Primitives to construct a stream from pure values or monadic actions.
54 -- All other stream construction and generation combinators described later
55 -- can be expressed in terms of these primitives. However, the special
56 -- versions provided in this module can be much more efficient in some
57 -- cases. Users can create custom combinators using these primitives.
93 -- * Combining Two Streams
109 -- XXX is "bind/concatFor" better to have than crossWith?
110 -- crossWith f xs1 xs2 = concatFor xs1 (\x -> fmap (f x) xs2)
114 -- , CrossStreamK (..)
116 -- * Stream of streams
122 -- * Buffered Operations
128import Streamly.Internal.Data.Stream.StreamK
129import Prelude hiding (reverse, zipWith, mapM, dropWhile, take)
131#include "DocTestDataStreamK.hs"
135-- Continuation passing style (CPS) stream implementation. The 'K' in 'StreamK'
136-- stands for Kontinuation.
138-- StreamK can be constructed like lists, except that they use 'nil' instead of
139-- '[]' and 'cons' instead of ':'.
141-- `cons` adds a pure value at the head of the stream:
143-- >>> import Streamly.Data.StreamK (StreamK, cons, consM, nil)
144-- >>> stream = 1 `cons` 2 `cons` nil :: StreamK IO Int
146-- You can use operations from "Streamly.Data.Stream" for StreamK as well by
147-- converting StreamK to Stream ('toStream'), and vice-versa ('fromStream').
149-- >>> Stream.fold Fold.toList $ StreamK.toStream stream -- IO [Int]
152-- `consM` adds an effect at the head of the stream:
154-- >>> stream = effect 1 `consM` effect 2 `consM` nil
155-- >>> Stream.fold Fold.toList $ StreamK.toStream stream
160-- == Exception Handling
162-- There are no native exception handling operations in the StreamK module,
163-- please convert to 'Stream' type and use exception handling operations from
164-- "Streamly.Data.Stream".
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