| Copyright | (c) 2017 Composewell Technologies |
|---|---|
| License | BSD3 |
| Maintainer | streamly@composewell.com |
| Stability | experimental |
| Portability | GHC |
| Safe Haskell | None |
| 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 :: Type -> Type) a = SerialT {
- getSerialT :: Stream m a
- toStreamK :: forall (m :: Type -> Type) a. SerialT m a -> Stream m a
- fromStreamK :: forall (m :: Type -> Type) a. Stream m a -> SerialT m a
- type Serial = SerialT IO
- serial :: forall (m :: Type -> Type) a. SerialT m a -> SerialT m a -> SerialT m a
- newtype WSerialT (m :: Type -> Type) a = WSerialT {
- getWSerialT :: Stream m a
- type WSerial = WSerialT IO
- wSerial :: forall (m :: Type -> Type) a. WSerialT m a -> WSerialT m a -> WSerialT m a
- wSerialFst :: forall (m :: Type -> Type) a. WSerialT m a -> WSerialT m a -> WSerialT m a
- wSerialMin :: forall (m :: Type -> Type) a. WSerialT m a -> WSerialT m a -> WSerialT m a
- consMWSerial :: Monad m => m a -> WSerialT m a -> WSerialT m a
- cons :: forall a (m :: Type -> Type). a -> SerialT m a -> SerialT m a
- consM :: Monad m => m a -> SerialT m a -> SerialT m a
- repeat :: forall (m :: Type -> Type) a. 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 :: forall (m :: Type -> Type) a b. 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
newtype SerialT (m :: Type -> Type) a Source #
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
Serial interleaving stream
newtype WSerialT (m :: Type -> Type) a Source #
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
| IsStream WSerialT Source # | |||||
Defined in Streamly.Internal.Data.Stream.IsStream.Type | |||||
| MonadTrans WSerialT Source # | |||||
Defined in Streamly.Internal.Data.Stream.Serial | |||||
| MonadReader r m => MonadReader r (WSerialT m) Source # | |||||
| MonadState s m => MonadState s (WSerialT m) Source # | |||||
| MonadIO m => MonadIO (WSerialT m) Source # | |||||
Defined in Streamly.Internal.Data.Stream.Serial | |||||
| (Foldable m, Monad m) => Foldable (WSerialT m) Source # | |||||
Defined in Streamly.Internal.Data.Stream.Serial Methods fold :: Monoid m0 => WSerialT m m0 -> m0 # foldMap :: Monoid m0 => (a -> m0) -> WSerialT m a -> m0 # foldMap' :: Monoid m0 => (a -> m0) -> WSerialT m a -> m0 # foldr :: (a -> b -> b) -> b -> WSerialT m a -> b # foldr' :: (a -> b -> b) -> b -> WSerialT m a -> b # foldl :: (b -> a -> b) -> b -> WSerialT m a -> b # foldl' :: (b -> a -> b) -> b -> WSerialT m a -> b # foldr1 :: (a -> a -> a) -> WSerialT m a -> a # foldl1 :: (a -> a -> a) -> WSerialT m a -> a # toList :: WSerialT m a -> [a] # null :: WSerialT m a -> Bool # length :: WSerialT m a -> Int # elem :: Eq a => a -> WSerialT m a -> Bool # maximum :: Ord a => WSerialT m a -> a # minimum :: Ord a => WSerialT m a -> a # | |||||
| Traversable (WSerialT Identity) Source # | |||||
Defined in Streamly.Internal.Data.Stream.Serial Methods traverse :: Applicative f => (a -> f b) -> WSerialT Identity a -> f (WSerialT Identity b) # sequenceA :: Applicative f => WSerialT Identity (f a) -> f (WSerialT Identity a) # mapM :: Monad m => (a -> m b) -> WSerialT Identity a -> m (WSerialT Identity b) # sequence :: Monad m => WSerialT Identity (m a) -> m (WSerialT Identity a) # | |||||
| Monad m => Applicative (WSerialT m) Source # | |||||
Defined in Streamly.Internal.Data.Stream.Serial | |||||
| Monad m => Functor (WSerialT m) Source # | |||||
| Monad m => Monad (WSerialT m) Source # | |||||
| NFData1 (WSerialT Identity) Source # | |||||
Defined in Streamly.Internal.Data.Stream.Serial | |||||
| MonadThrow m => MonadThrow (WSerialT m) Source # | |||||
Defined in Streamly.Internal.Data.Stream.Serial Methods throwM :: (HasCallStack, Exception e) => e -> WSerialT m a # | |||||
| a ~ Char => IsString (WSerialT Identity a) Source # | |||||
Defined in Streamly.Internal.Data.Stream.Serial Methods fromString :: String -> WSerialT Identity a # | |||||
| Monoid (WSerialT m a) Source # | |||||
| Semigroup (WSerialT m a) Source # | |||||
| IsList (WSerialT Identity a) Source # | |||||
Defined in Streamly.Internal.Data.Stream.Serial Associated Types
| |||||
| Read a => Read (WSerialT Identity a) Source # | |||||
| Show a => Show (WSerialT Identity a) Source # | |||||
| NFData a => NFData (WSerialT Identity a) Source # | |||||
Defined in Streamly.Internal.Data.Stream.Serial | |||||
| Eq a => Eq (WSerialT Identity a) Source # | |||||
| Ord a => Ord (WSerialT Identity a) Source # | |||||
Defined in Streamly.Internal.Data.Stream.Serial Methods compare :: WSerialT Identity a -> WSerialT Identity a -> Ordering # (<) :: WSerialT Identity a -> WSerialT Identity a -> Bool # (<=) :: WSerialT Identity a -> WSerialT Identity a -> Bool # (>) :: WSerialT Identity a -> WSerialT Identity a -> Bool # (>=) :: WSerialT Identity a -> WSerialT Identity a -> Bool # max :: WSerialT Identity a -> WSerialT Identity a -> WSerialT Identity a # min :: WSerialT Identity a -> WSerialT Identity a -> WSerialT Identity a # | |||||
| type Item (WSerialT Identity a) Source # | |||||
Defined in Streamly.Internal.Data.Stream.Serial | |||||
wSerial :: forall (m :: Type -> Type) a. 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 :: forall (m :: Type -> Type) a. 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 #
The fromList function constructs the structure l from the given
list of Item l
Elimination
toList :: IsList l => l -> [Item l] #
The toList function extracts a list of Item l from the structure l.
It should satisfy fromList . toList = id.