| Copyright | (c) 2017 Composewell Technologies |
|---|---|
| License | BSD3 |
| Maintainer | streamly@composewell.com |
| Stability | experimental |
| Portability | GHC |
| Safe Haskell | Safe-Inferred |
| Language | Haskell2010 |
Streamly.Internal.Data.Stream.Serial
Description
Deprecated: Please use Streamly.Internal.Data.Stream from streamly-core package instead.
To run examples in this module:
>>>import qualified Streamly.Prelude as Stream
Synopsis
- newtype SerialT m a = SerialT {
- getSerialT :: Stream m a
- toStreamK :: SerialT m a -> Stream m a
- fromStreamK :: Stream m a -> SerialT m a
- type Serial = SerialT IO
- serial :: SerialT m a -> SerialT m a -> SerialT m a
- newtype WSerialT m a = WSerialT {
- getWSerialT :: Stream m a
- type WSerial = WSerialT IO
- wSerial :: WSerialT m a -> WSerialT m a -> WSerialT m a
- wSerialFst :: WSerialT m a -> WSerialT m a -> WSerialT m a
- wSerialMin :: WSerialT m a -> WSerialT m a -> WSerialT m a
- consMWSerial :: Monad m => m a -> WSerialT m a -> WSerialT m a
- cons :: a -> SerialT m a -> SerialT m a
- consM :: Monad m => m a -> SerialT m a -> SerialT m a
- repeat :: Monad m => a -> SerialT m a
- unfoldrM :: Monad m => (b -> m (Maybe (a, b))) -> b -> SerialT m a
- fromList :: IsList l => [Item l] -> l
- toList :: IsList l => l -> [Item l]
- map :: Monad m => (a -> b) -> SerialT m a -> SerialT m b
- mapM :: Monad m => (a -> m b) -> SerialT m a -> SerialT m b
Serial appending stream
For SerialT streams:
(<>) =serial--Semigroup(>>=) = flip .concatMapWithserial--Monad
A single Monad bind behaves like a for loop:
>>>:{IsStream.toList $ do x <- IsStream.fromList [1,2] -- foreach x in stream return x :} [1,2]
Nested monad binds behave like nested for loops:
>>>:{IsStream.toList $ do x <- IsStream.fromList [1,2] -- foreach x in stream y <- IsStream.fromList [3,4] -- foreach y in stream return (x, y) :} [(1,3),(1,4),(2,3),(2,4)]
Since: 0.2.0 (Streamly)
Since: 0.8.0
Constructors
| SerialT | |
Fields
| |
Instances
fromStreamK :: Stream m a -> SerialT m a Source #
Serial interleaving stream
For WSerialT streams:
(<>) =wSerial--Semigroup(>>=) = flip .concatMapWithwSerial--Monad
Note that <> is associative only if we disregard the ordering of elements
in the resulting stream.
A single Monad bind behaves like a for loop:
>>>:{IsStream.toList $ IsStream.fromWSerial $ do x <- IsStream.fromList [1,2] -- foreach x in stream return x :} [1,2]
Nested monad binds behave like interleaved nested for loops:
>>>:{IsStream.toList $ IsStream.fromWSerial $ do x <- IsStream.fromList [1,2] -- foreach x in stream y <- IsStream.fromList [3,4] -- foreach y in stream return (x, y) :} [(1,3),(2,3),(1,4),(2,4)]
It is a result of interleaving all the nested iterations corresponding to
element 1 in the first stream with all the nested iterations of element
2:
>>>import Streamly.Prelude (wSerial)>>>IsStream.toList $ IsStream.fromList [(1,3),(1,4)] `IsStream.wSerial` IsStream.fromList [(2,3),(2,4)][(1,3),(2,3),(1,4),(2,4)]
The W in the name stands for wide or breadth wise scheduling in
contrast to the depth wise scheduling behavior of SerialT.
Since: 0.2.0 (Streamly)
Since: 0.8.0
Constructors
| WSerialT | |
Fields
| |
Instances
wSerial :: WSerialT m a -> WSerialT m a -> WSerialT m a infixr 6 Source #
Interleaves two streams, yielding one element from each stream alternately. When one stream stops the rest of the other stream is used in the output stream.
This gives exponential priority to earlier streams than the ones joining
later. Because of exponential weighting it can be used with concatMapWith.
Not fused
Construction
repeat :: Monad m => a -> SerialT m a Source #
Generate an infinite stream by repeating a pure value.
unfoldrM :: Monad m => (b -> m (Maybe (a, b))) -> b -> SerialT m a Source #
Build a stream by unfolding a monadic step function starting from a
seed. The step function returns the next element in the stream and the next
seed value. When it is done it returns Nothing and the stream ends. For
example,
let f b =
if b > 3
then return Nothing
else print b >> return (Just (b, b + 1))
in drain $ unfoldrM f 0
0 1 2 3
Pre-release
fromList :: IsList l => [Item l] -> l Source #
The fromList function constructs the structure l from the given
list of Item l
Elimination
toList :: IsList l => l -> [Item l] Source #
The toList function extracts a list of Item l from the structure l.
It should satisfy fromList . toList = id.